java.lang.SecurityException异常尝试从Android的联系人URI阅读

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

我想读取联系人姓名,电话号码的,并从 ContactsContract URI的电子邮件,而我得到一个 SecurityException异常。我已经设置了的Andr​​oidManifest.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阅读

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

发布评论

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

>www.elefans.com

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