This is my code in OnCreate() method :
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.RECIEVE_SMS)) {
} else {
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},1);
}
And in my onRequestPermissionsResult() method :
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 1:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
init();
}else{
finish();
}
And my Manifest file has the following permissions
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
But i'm not getting the dialog asking for the permission and i can't figure out the problem?
if your app targeting Android 6.0 and above than add runtime permission
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app
add runtime permission using below code for READ_SMS
and than handle result like this