i recently updated my app to support android 6 marshmallow. i followed the instruction on https://developer.android.com/training/permissions/requesting.html
and add
You need a permission for api level 23+, google reworked the permission system so the app user can grant and revoke permissions after installing your app
final private int REQUEST_CODE_ASK_PERMISSIONS = 123;
if(Build.VERSION.SDK_INT < 23){
//your code here
}else {
requestContactPermission();
}
private void requestContactPermission() {
int hasContactPermission =ActivityCompat.checkSelfPermission(context,Manifest.permission.RECEIVE_SMS);
if(hasContactPermission != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions(Context, new String[] {Manifest.permission.RECEIVE_SMS}, PERMISSION_REQUEST_CODE);
}else {
//Toast.makeText(AddContactsActivity.this, "Contact Permission is already granted", Toast.LENGTH_LONG).show();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_ASK_PERMISSIONS:
// Check if the only required permission has been granted
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.i("Permission", "Contact permission has now been granted. Showing result.");
Toast.makeText(this,"Contact Permission is Granted",Toast.LENGTH_SHORT).show();
} else {
Log.i("Permission", "Contact permission was NOT granted.");
}
break;
}
}