The main error in AndroidManifest.xml for obtaining permission to receive SMS

I know that this has been requested a few dozen times, but I still get a permission error with this xml configuration. I looked at other answers to this. I am using API level 23. Can someone please point out an error? The error is obvious:

09-12 09: 13: 40.016 1295-1309 /? W / BroadcastQueue: permission denied: receiving intent {act = android.provider.Telephony.SMS_RECEIVED flg = 0x8000010 (has additional functions)} 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"/> 

+5
source share
8 answers

The problem lies in the new permission model for Android M (api 23):

Quickview

  • If your application targets the M Preview SDK, it offers users to grant permissions at runtime, rather than installation time.
  • Users can revoke permissions at any time on the app’s settings screen.
  • Your application should verify that it has the permissions it needs every time it starts.

For documentation on SMS documents, an example is given:

For example, suppose an application shows in its manifest that it needs SEND_SMS and RECEIVE_SMS, which both belong to android.permission-group.SMS. When an application needs to send a message, it requests permission from SEND_SMS. The system displays a dialog to the user asking if the application can access SMS. If the user agrees, the system provides the application with the requested permission SEND_SMS. Later, the application requests RECEIVE_SMS. The system automatically grants this permission because the user has already approved the permission in the same permission group.

Solutions:

  • The correct way is to request permission first.
  • lazy way - set targetSdk 22
+16
source

@Richard Green : Your Logcat Throws Out

Disclaimer: obtaining the intent {act = android.provider.Telephony.SMS_RECEIVED flg = 0x8000010 (there are additional functions)} to com.example.richard.simplesmstoast / .SmsReceiver requires android.permission.RECEIVE_SMS due to the sender com.android. phone

Permission - a restriction that restricts access to part of the code or to data on the device. A restriction is imposed to protect critical data and code that may be misused to distort or damage user experience.

I guess the permission problem.

Please add below Manifest -Permations Above Application .

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

Hope this helps you.

+2
source

First, the RECEIVE_SMS permission must be declared in AndroidManifest.xml.

 ... <uses-permission android:name="android.permission.RECEIVE_SMS" /> ... <receiver android:name=".receiver.IncomingSmsReceiver" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> 

Then, starting at API level 23, we need to request RECEIVE_SMS permission at runtime. This is important to note. https://developer.android.com/training/permissions/requesting.html

 public class MainActivity extends AppCompatActivity { private static final int PERMISSIONS_REQUEST_RECEIVE_SMS = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Request the permission immediately here for the first time run requestPermissions(Manifest.permission.RECEIVE_SMS, PERMISSIONS_REQUEST_RECEIVE_SMS); } private void requestPermissions(String permission, int requestCode) { // Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) { // Show an explanation to the user *asynchronously* -- don't block // this thread waiting for the user response! After the user // sees the explanation, try again to request the permission. Toast.makeText(this, "Granting permission is necessary!", Toast.LENGTH_LONG).show(); } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode); // requestCode is an // app-defined int constant. The callback method gets the // result of the request. } } } @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case PERMISSIONS_REQUEST_RECEIVE_SMS: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! Do the // contacts-related task you need to do. NotificationUtil.getInstance().show(this, NotificationUtil.CONTENT_TYPE.INFO, getResources().getString(R.string.app_name), "Permission granted!"); } else { // permission denied, boo! Disable the // functionality that depends on this permission. NotificationUtil.getInstance().show(this, NotificationUtil.CONTENT_TYPE.ERROR, getResources().getString(R.string.app_name), "Permission denied! App will not function correctly"); } return; } // other 'case' lines to check for other // permissions this app might request } } } 

Hope this helps you.

+1
source

Your permission should be placed outside and in front of the application tag:

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

Add permission inside the application tag, for example ..

 <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <uses-permission android:name="android.permission.RECEIVE_SMS"/> <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> 
0
source
  • If you are targeting Marshmallow, you need to request permission at runtime other than the manifest.

Manifesto -

  <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 !!!"); } } } 
0
source

it worked for me ... check it out maybe this 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
source
 //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 resolving WRTIE_SMS

-1
source

All Articles