Problem was in new Android 6+ feature: Request Permission at Runtime.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
if (!permissionRequestInProgress) {
permissionRequestInProgress = true;
new Handler().post(new Runnable() {
@Override
public void run() {
if (ContextCompat.checkSelfPermission(RootActivity.this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(RootActivity.this,
new String[]{Manifest.permission.CAMERA},
CAMERA_PERMISSION_REQUEST);
} else {
//we got it
}
}
});
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case CAMERA_PERMISSION_REQUEST:
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted
//we got it
} else {
// permission denied
}
permissionRequestInProgress = false;
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}