【问题标题】:Android reading sms fails even having permissionAndroid读取短信即使获得许可也失败
【发布时间】:2015-09-19 08:22:37
【问题描述】:

我的应用程序有一个类似这样的 manifers:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ssh.com.smsassistant" >

    <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" >
        <activity
            android:name=".MainActivity"
            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>

当我尝试使用以下代码阅读短信时:

Uri message = Uri.parse("content://sms/");
ContentResolver cr = mActivity.getContentResolver();
Cursor c = cr.query(message, null, null, null, null);

它失败并出现以下异常:

Caused by: java.lang.SecurityException: Permission Denial: 
reading com.android.providers.telephony.SmsProvider uri content://sms/ 
from pid=6670, uid=10059 requires android.permission.READ_SMS, or 
grantUriPermission()

有什么想法吗,伙计们?

【问题讨论】:

标签: java android permissions sms


【解决方案1】:

我测试了您的代码和您的许可。它可以正常工作。 清理并重建您的项目并再次测试。

【讨论】:

    【解决方案2】:

    我的应用在 Android 6.0 系统上发生了这种情况,所以我将目标 SDK 设置为 22,它使用旧的权限系统。

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

    【讨论】:

      猜你喜欢
      • 2019-06-05
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-03
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多