java.lang.SecurityException 尝试从 Android 联系人 URI 读取

编程入门 行业动态 更新时间:2024-10-17 11:31:15
本文介绍了java.lang.SecurityException 尝试从 Android 联系人 URI 读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从 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>`

以下是应用代码:

@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()):

I get a security exception on the last line (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.

推荐答案

确保将其添加到应用程序标记之外.在 Ubuntu 上使用 Eclipse 为 2.3.3 的目标平台进行开发时,我在日志文件中遇到了权限失败,这表明我在处理类似的事情时需要这一行.直到我将 *uses-permission...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 读取

本文发布于:2023-11-27 04:04:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:联系人   lang   java   SecurityException   URI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!