Selecting a contact and retrieveing phone number
<p>I'm trying to get a code working to select a contact and retrieve the phone number.
I found a piece of code which works great on the Emulator (android version 2.3.3) and on my brother's phone (Jelly bean) but not my on own device (android 2.3.4)</p>

<p>Here's the code:
To go to contacts</p>

<pre><code>    public void onClick(View arg0) {
        // TODO Auto-generated method stub
         Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
         intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
         startActivityForResult(intent, 1);      
    }
</code></pre>

<p>When coming back from contacts:</p>

<pre><code>@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (data != null) {
        Uri uri = data.getData();

        if (uri != null) {
            Cursor c = null;
            try {
                c = getContentResolver().query(uri, new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER},
                        null, null, null);

                if (c != null &amp;&amp; c.moveToFirst()) {
                    String number = c.getString(0);
                    //int type = c.getInt(1);
                    showSelectedNumber(0, number);
                }
            } finally {
                if (c != null) {
                    c.close();
                }
            }
        }
    }
}

public void showSelectedNumber(int type, String number) {
    Toast.makeText(this,number, Toast.LENGTH_LONG).show();      
}
</code></pre>

<p>Again, this works on the emulator (android 2.3.4) and on Jelly bean but not on my device (android 2.3.5)</p>

<p>This is what comes out from the log:</p>

<pre><code>10-10 22:07:15.775: E/AndroidRuntime(5075): FATAL EXCEPTION: main
10-10 22:07:15.775: E/AndroidRuntime(5075): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/data/2848 (has extras) }} to activity {com.example.omer/com.example.omer.SmsInfo}: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.HtcContactsProvider2 uri content://com.android.contacts/data/2848 from pid=5075, uid=10125 requires android.permission.READ_CONTACTS
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.app.ActivityThread.deliverResults(ActivityThread.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.app.ActivityThread.handleSendResult(ActivityThread.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.app.ActivityThread.access$2000(ActivityThread.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.os.Handler.dispatchMessage(Handler.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.os.Looper.loop(Looper.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.app.ActivityThread.main(ActivityThread.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at java.lang.reflect.Method.invokeNative(Native Method)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at java.lang.reflect.Method.invoke(Method.java:507)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at dalvik.system.NativeStart.main(Native Method)
10-10 22:07:15.775: E/AndroidRuntime(5075): Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.HtcContactsProvider2 uri content://com.android.contacts/data/2848 from pid=5075, uid=10125 requires android.permission.READ_CONTACTS
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.os.Parcel.readException(Parcel.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.content.ContentProviderProxy.query(ContentProviderNative.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.content.ContentResolver.query(ContentResolver.java)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at com.example.omer.SmsInfo.onActivityResult(SmsInfo.java:87)
10-10 22:07:15.775: E/AndroidRuntime(5075):     at android.app.Activity.dispatchActivityResult(Activity.java)
</code></pre>

<p>10-10 22:07:15.775: E/AndroidRuntime(5075):     ... 12 more</p>
