views:

33

answers:

1

I am writting my application using api 1.6. The code runs just fine on the emulators 1.6-2.2.

But when I try to debugging it on my device which runs 2.1 data.getData() returns null. I have this in the AndroidManifest.xml <uses-permission android:name="android.permission.READ_CONTACTS"/>

Any one have any thoughts. I am new to android, thanks.

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btnTest = (Button) findViewById(R.id.btnTest);
        btnTest.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);

                startActivityForResult(intent, ACTIVITY_PICK_CONTACT);
            }
        });
    }

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
        case (ACTIVITY_PICK_CONTACT):
            if (resultCode == Activity.RESULT_OK) {
                // This is where it is broke
                            Uri uri = data.getData();

                Intent intent = new Intent(this, PickContactInfo.class);
                intent.putExtra(Keys.CONTACT_URI, uri.toString());
                startActivity(intent);
            }
            break;
        }

    };
A: 

There are a few possibilities.

First, try switching from People.CONTENT_URI to Contacts.CONTENT_URI. I have not had a problem with that returning a null contact. Here is a sample project.

Second, make sure that the contact you are picking is one that is on the device itself (vs. one synced to it from Facebook, Exchange, etc.). The old API only works with on-device contacts.

If none of that helps, there may be a bug with the firmware in your device. I'd be interested to know, in this case, what device this is.

CommonsWare
I was developing it with 1.6 API and have just decided to go with 2.0 since the contact stuff changed so much between the 2 versions. Once I made the change and used Contact.CONTENT_URI it works as it would expect it to. Could never get it to work in 1.6 using Contacts.CONTENT_URI It was telling me could not find Activity. Thanks for you help though, It eventually led me to a solution.
J.13.L