Reputation: 2062
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"/>
Upvotes: 5
Views: 11398
Reputation: 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
Upvotes: -1
Reputation: 450
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 !!!");
}
}
}
Upvotes: 0
Reputation: 75788
@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 .
Upvotes: 2
Reputation: 6223
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:
Upvotes: 17
Reputation: 221
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>
Upvotes: -1
Reputation: 1875
Your permission should be placed outside and before your application tag:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
Upvotes: 0