这很奇怪,我已经搜索了论坛。
在我的主类中,我有一个按钮 onClick 将启动联系人应用程序,如下所示。当我单击该按钮时,会显示他的联系人列表,但只要我点击一个联系人,就会引发安全异常。
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);
}
我检查了清单,并尝试了在应用程序、活动等中放置使用权限标签的所有组合。但没有任何效果。这是我的清单。
<?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>
安全例外:
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
任何帮助将不胜感激。我正在 Android 2.1 Sony experia S10 mini 上尝试这个。