0

I have a manifers for my app like this:

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

And when I try to read sms using following code:

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

it fails with the following exception:

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

Any ideas, guys?

Titus
  • 22,031
  • 1
  • 23
  • 33
Damask
  • 1,754
  • 1
  • 13
  • 24
  • [I guess this question may help you][1] [1]: http://stackoverflow.com/questions/848728/how-can-i-read-sms-messages-from-the-inbox-programmatically-in-android – KTang Sep 19 '15 at 08:49

2 Answers2

0

I tested your code and your permission. it works without any problem. clean and rebuild your project and test again.

Milad Nouri
  • 1,587
  • 1
  • 21
  • 32
0

It happened to my app on the Android 6.0 system, so I set target SDK to 22 which uses the old permissions system.

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

Pang
  • 9,564
  • 146
  • 81
  • 122
A_xun_A
  • 1
  • 2