android本地权限Androidmanifest短信阅读

时间:2015-09-20 10:18:43

标签: android

配置:

  • Studio 1.3
  • API 23

我正在学习Android并开始从事SMS阅读一个简单的项目。

我已在AndroidManifest.xml的SMS_READ中添加了权限。仍然在运行模拟器时,它会为SMS_READ抛出错误权限拒绝。

我不确定模拟器问题或API 23级权限是否更改?

错误:

Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider uri content://sms/inbox from pid=1900, uid=10058 requires android.permission.READ_SMS, or grantUriPermission()
            at android.os.Parcel.readException(Parcel.java:1599)
            at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
            at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
            at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
            at android.content.ContentResolver.query(ContentResolver.java:491)
            at android.content.ContentResolver.query(ContentResolver.java:434)
            at com.example.gunda.mysmsreadapp.MainActivity.fetchInbox(MainActivity.java:68)
            at com.example.gunda.mysmsreadapp.MainActivity.onCreate(MainActivity.java:36)
            at android.app.Activity.performCreate(Activity.java:6237)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
            at android.app.ActivityThread.-wrap11(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

这是清单xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.gunda.mysmsreadapp" >
    <uses-permission android:name="android.permission.READ_SMS"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        android:exported="true"

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <!--<action android:name="android.provider.Telephony.READ_SMS" />-->
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

3 个答案:

答案 0 :(得分:3)

最后我找到了答案: API 23(android 6.o)需要不同类型的权限.....

http://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

答案 1 :(得分:0)

权限名称是READ_SMS,您似乎正在使用SMS_READ。

答案 2 :(得分:0)

仅在此处进行更新-如果您想使用READ_SMS权限,则要求Google声明您的应用为何需要此权限,然后他们才可以访问您的应用。阅读此support.google.com/googleplay/android-developer/answer/9214102