I'm getting contacts from the ContactPicker from various devices but While trying to fetch contact from HTC devices I'm gettting the below exception :
java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.HtcContactsProvider2 uri content://com.android.contacts/data/719 from pid=8344, uid=10214 requires android.permission.READ_CONTACTS, or grantUriPermission()
Permissions that I have given is:
android.permission.READ_CONTACTS
Below is the code that I have implemented:
Intent intent = new Intent(Intent.ACTION_PICK,
Phone.CONTENT_URI);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, 101);
@Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
// TODO Auto-generated method stub
super.onActivityResult(arg0, arg1, arg2);
if (arg1 == Activity.RESULT_OK) {
Uri contactData = arg2.getData();
ContentResolver cur = getContentResolver();
Cursor cursorID = getContentResolver().query(contactData,
new String[] { ContactsContract.Contacts._ID }, null, null,
null);
grantUriPermission("ContactsContract.CommonDataKinds.Phone.CONTENT_URI", contactData, 2);
Cursor c = cur.query(contactData, null, null, null, null);
if (c.moveToFirst()) {
String name = c
.getString(c
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String number = c
.getString(c
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(getApplicationContext(),
"" + name + " " + number, 4000).show();
}
}
}
Any help is appreciated.
Aucun commentaire:
Enregistrer un commentaire