I developed and Instant App which one I would like to take a picture with the camera. Everything work if I launch the Installed App. But with Instant App, I get the following error :
java.lang.SecurityException: Not allowed to start activity Intent { act=android.media.action.IMAGE_CAPTURE launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 }
Here my code :
AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
Activity :
private static int CAMERA_REQUEST = 1234;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_goodbye);
findViewById(R.id.mainButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startCamera();
}
});
}
private void startCamera() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMERA_REQUEST);
}
} else {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
startCamera();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
Bitmap bmp = (Bitmap)data.getExtras().get("data");
((ImageView)findViewById(R.id.mainImageView)).setImageBitmap(bmp);
}
}
I develop on device (samsung) with Android 7.0. I checked available permission and Camera is that's why it's should work. (https://developer.android.com/topic/instant-apps/faqs.html#available-permissions) Thanks in advance.