我想读取联系人姓名,电话号码的,并从 ContactsContract URI的电子邮件,而我得到一个 SecurityException异常。我已经设置了的AndroidManifest.xml 文件的权限:
I am trying to read Contact names, phone #'s, and emails from the ContactsContract URI, and I am getting a SecurityException when I try to run the program. I have set the permission in the AndroidManifest.xml file:
<manifest xmlns:android="schemas.android/apk/res/android" package="edu.smumn.cs394" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> **<uses-permission android:name="android.pemission.READ_CONTACTS"/>** <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ReadPhoneNumbers" 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>`
下面是应用程序code:
The following is the application code:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contact_list); ContentResolver resolver = getContentResolver(); Cursor c = resolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); //[...] Work through data here`
我得到的最后一行安全异常( resolver.query()):
`03-08 07:41:40.812: ERROR/AndroidRuntime(416): FATAL EXCEPTION: main 03-08 07:41:40.812: ERROR/AndroidRuntime(416): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.smumn.cs394/edu.smumn.cs394.ReadPhoneNumbers}: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/contacts from pid=416, uid=10037 requires android.permission.READ_CONTACTS [...] 03-08 07:41:40.812: ERROR/AndroidRuntime(416): Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/contacts from pid=416, uid=10037 requires android.permission.READ_CONTACTS [...] 03-08 07:41:40.812: ERROR/AndroidRuntime(416): at edu.smumn.cs394.ReadPhoneNumbers.onCreate(ReadPhoneNumbers.java:30)
[...]`
[...]`
我一定是失去了一些东西,但我想不出什么。
I must be missing something, but I can't figure out what.
推荐答案请确保你的应用程序标签之外添加。虽然开发2.3.3使用Eclipse在Ubuntu的目标平台,我在这表示我需要这个确切的行,当工作在类似的日志文件权限失败。直到我搬到了*使用,许可...... READ_CONTACTS *线到事情的来龙去脉应用程序标记之外。
Make sure you add it outside of the application tag. While developing for a target platform of 2.3.3 using Eclipse on Ubuntu, I had permission failures in the log file that indicated I needed this exact line while working on something similar. It wasn't until I moved the *uses-permission...READ_CONTACTS* line to outside the application tag that things worked.
更多推荐
java.lang.SecurityException异常尝试从Android的联系人URI阅读
发布评论