簡體   English   中英

Android讀取短信即使獲得許可也失敗

[英]Android reading sms fails even having permission

我的應用程式中有一個manifer,如下所示:

<?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()

大家有什么想法嗎?

我測試了您的代碼和您的許可。 它的工作沒有任何問題。 清理並重建項目,然后再次測試。

我的應用程序在Android 6.0系統上發生了變化,因此我將目標SDK設置為使用舊權限系統的22。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM