为了账号安全,请及时绑定邮箱和手机立即绑定

用Android Studio走老师代码程序就崩了,权限都已经配置了

08-09 21:31:07.895 22138-22138/com.example.a25242.contentproviderdemo E/AndroidRuntime: FATAL EXCEPTION:main Process:com.example.a25242.contentproviderdemo, PID: 22138 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.a25242.contentproviderdemo/com.example.a25242.contentproviderdemo.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{a980a9b 22138:com.example.a25242.contentproviderdemo/u0a168} (pid=22138, uid=10168) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
                                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
                                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
                                                                                            at android.app.ActivityThread.access$900(ActivityThread.java:153)
                                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
                                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                            at android.os.Looper.loop(Looper.java:148)
                                                                                            at android.app.ActivityThread.main(ActivityThread.java:5438)
                                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
                                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
                                                                                         Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{a980a9b 22138:com.example.a25242.contentproviderdemo/u0a168} (pid=22138, uid=10168) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
                                                                                            at android.os.Parcel.readException(Parcel.java:1620)
                                                                                            at android.os.Parcel.readException(Parcel.java:1573)
                                                                                            at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3553)
                                                                                            at

正在回答

5 回答

if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this,
            new String[]{Manifest.permission.READ_CONTACTS}, 1);
} else {
}
//加上这个就可以了


2 回复 有任何疑惑可以回复我~

应该是还少一个写入的

0 回复 有任何疑惑可以回复我~

这问题似乎跟我一样的

0 回复 有任何疑惑可以回复我~
#1

月满轩尼诗

Cursor c = cr.query(Contacts.CONTENT_URI, new String[]{Contacts._ID, Contacts.DISPLAY_NAME}, null, null,null); 执行到这里就崩了
2016-09-14 回复 有任何疑惑可以回复我~
#2

Rick_James 回复 月满轩尼诗

解决没有啊
2016-11-05 回复 有任何疑惑可以回复我~
#3

12313凯皇

我也是啊 加了权限还是要报这个错很懵啊
2018-07-20 回复 有任何疑惑可以回复我~
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.administrator.contendprovider">
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>


0 回复 有任何疑惑可以回复我~

http://img1.sycdn.imooc.com//57aaa2960001e07008900339.jpg应该权限没加上

0 回复 有任何疑惑可以回复我~
#1

sorgs

只加这句可以么? <uses-permission android:name="android.permission.READ_CONTACTS"/>
2016-08-16 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android攻城狮的第二门课(第3季)
  • 参与学习       74912    人
  • 解答问题       420    个

手势识别、数据存储和4大组件,让你牢牢掌握之前的基础知识点

进入课程

用Android Studio走老师代码程序就崩了,权限都已经配置了

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信