5

I know that this has been asked a dozen times before, but I still get the permission error with this xml config. I have scoured the other responses on this. I am using API level 23. Can someone please point out the mistake ? The error is the obvious:

09-12 09:13:40.016 1295-1309/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x8000010 (has extras) } to com.example.richard.simplesmstoast/.SmsReceiver requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)

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

    <receiver
        android:name=".SmsReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter android:priority="999" >
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
</application>

<uses-permission android:name="android.permission.RECEIVE_SMS"/>

6
  • Try placing your <uses-permission android:name="android.permission.RECEIVE_SMS"/> before the <application> tag Sep 12, 2015 at 9:16
  • @Vaibhav .. tried that... I've put it all sorts of places :-/ Sep 12, 2015 at 9:17
  • try making the following changes to your receiver, and if you are reading the SMS you might want to add <uses-permission android:name="android.permission.READ_SMS" /> as well <receiver android:name=".SmsReceiver" android:enabled="true" android:exported="true" android:permission="android.permission.BROADCAST_SMS"> <intent-filter android:priority="1000"> <action android:name="android.provider.Telephony.SMS_RECEIVED"/> </intent-filter> </receiver> Sep 12, 2015 at 9:32
  • @Vaibhav ... Nope :-( Sep 12, 2015 at 9:34
  • 2
    "Hey, Where Did My Permission Go?": commonsware.com/blog/2015/08/31/… Sep 18, 2015 at 0:10

6 Answers 6

17
+50

Problem lays in new permissions model for Android M (api 23):

Quickview

  • If your app targets the M Preview SDK, it prompts users to grant permissions at runtime, instead of install time.
  • Users can revoke permissions at any time from the app Settings screen.
  • Your app needs to check that it has the permissions it needs every time it runs.

for SMS case documentation bring an example:

For example, suppose an app lists in its manifest that it needs the SEND_SMS and RECEIVE_SMS permissions, which both belong to android.permission-group.SMS. When the app needs to send a message, it requests the SEND_SMS permission. The system shows the user a dialog box asking if the app can have access to SMS. If the user agrees, the system grants the app the SEND_SMS permission it requested. Later, the app requests RECEIVE_SMS. The system automatically grants this permission, since the user had already approved a permission in the same permission group.

Solutions:

  • right way - request permission at first.
  • lazy way - set targetSdk 22
1
  • I'm don't normally comment +1's on answers, but because of the open bounty I gotta say this is the right answer. I'm not sure how Android is going to manage compatibility with older apps running on M when it's released, but long term fixes will require adding permission checks throughout your code. Sep 20, 2015 at 4:07
2

@Richard Green : Your Logcat throws

Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x8000010 (has extras) } to com.example.richard.simplesmstoast/.SmsReceiver requires android.permission.RECEIVE_SMS due to sender com.android.phone

A permission is a restriction limiting access to a part of the code or to data on the device. The limitation is imposed to protect critical data and code that could be misused to distort or damage the user experience.

I assume that its permissions Problem .

Please add below Manifest -Permissions Above Application Tag .

   <uses-permission android:name="INTERNET"/>
   <uses-permission android:name="ACCESS_NETWORK_STATE"/>
   <uses-permission android:name="android.permission.WRITE_SMS" />
   <uses-permission android:name="android.permission.READ_SMS" />
   <uses-permission android:name="android.permission.RECEIVE_SMS" />

I hope it will helps you .

0
0

Your permission should be placed outside and before your application tag:

<uses-permission android:name="android.permission.RECEIVE_SMS" />
1
  • Pretty sure I tried that a few days ago; will re-attempt tonight when I am working on the PC with the SDK installed. Sep 14, 2015 at 10:48
0
  • If you are targeting Marshmallow then you have to request for runtime permission apart from manifest.

Manifest -

    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />

Java Activity class -

 final int REQ_CODE = 100;
void requestPermission(){
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED) {
        CTLogs.printLogs( "Permission is not granted, requesting");
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS,Manifest.permission.READ_SMS,Manifest.permission.RECEIVE_SMS}, REQ_CODE);

    } else {
        CTLogs.printLogs("Permission has been granted");
        readSMS();
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == REQ_CODE) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            CTLogs.printLogs("Permission has been granted");
            readSMS();
        } else {
            CTLogs.printLogs("Permission denied !!!");
        }
    }
}
-1

this worked for me... Check this out Maybe it will Help You

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo.Light.DarkActionBar" >
    <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>

    <receiver android:name="packageName" >
        <intent-filter >

            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>

    </receiver>
</application>

1
  • <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />enter code here <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.SEND_SMS"></uses-permission> Sep 14, 2015 at 12:20
-1
//Requesting permission
private void requestWritePermission() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_SMS) == PackageManager.PERMISSION_GRANTED)
        return;

    if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_SMS)) {
        //If the user has denied the permission previously your code will come to this block
        //Here you can explain why you need this permission
        //Explain here why you need this permission
    }
    //And finally ask for the permission
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_SMS}, WRITE_SMS_PERMISSION_CODE);
}

Error on WRTIE_SMS permission

1
  • 1
    Could you please elaborate your answer? Now it's not clear to understand.
    – Shashanth
    Jun 18, 2017 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.