Skip to content Skip to sidebar Skip to footer

Android : Java.lang.SecurityException: Permission Denial:

I have an android application that i need to receive sms and I found a certain tutorial that teaches how to do that but when I run it & I get android permission exception FAT

Solution 1:

Looks like its because new permissions system in android 6 try to use it before work with sms

if(ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED) {}

and this if you dont have permissions

ActivityCompat.requestPermissions(SmsActivity.this, new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);

I hope this helps


Solution 2:

If you are running it on marshmallow, you need to request the permission to read the sms at the runtime.

Here's the official doc : http://developer.android.com/training/permissions/requesting.html

You have to check the permission using ContextCompat.checkSelfPermission function. Then, if you don't have the permission,

request it via ActivityCompat.requestPermissions method and implement

public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) method to receive the user results.


Post a Comment for "Android : Java.lang.SecurityException: Permission Denial:"