This is totally weird and I've searched through the forums.
In my main class I have a button onClick will launch the contacts application as shown below. When I click the button, he contacts list is shown but as soon as I tap on a contact a security exception is thrown.
public void selectContacts(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PICK_CONTACT:
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
while (c.moveToNext()) {
String id = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
String phoneNumber = getPhoneNumber(id);
listOfContacts.add(phoneNumber);
}
} else {
System.out.println("User didn't pick a contact");
finish();
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
I've checked the manifest and have tried all combinations of placing the uses-permission tag, within the application, activity etc. But nothing works. Here's my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.company.letsmeet"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<uses-permision android:name="android.permission.SEND_SMS" />
<uses-permision android:name="android.permission.RECEIVE_SMS" />
<uses-permision android:name="android.permission.INTERNET" />
<uses-permision android:name="android.permission.READ_CONTACTS" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".LetsmeetActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The security exception :
05-04 11:26:39.950: E/AndroidRuntime(3861): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/7 }} to activity {in.company.letsmeet/in.company.letsmeet.LetsmeetActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.SemcContactsProvider2 uri content://com.android.contacts/contacts/7 from pid=3861, uid=10093 requires android.permission.READ_CONTACTS
Any help will be greatly appreciated. I'm trying this on Android 2.1 Sony experia S10 mini.
So guess what, I added the READ_CONTACTS permission in the Manifest GUI and it works. God I wasted an entire day on this. Hope others don't have to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With