I also developed an instant application that I would like to make with a camera. Everything works if I run the installed application . But with the 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 is 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 am developing a device (samsung) with Android 7.0. I checked the available resolution, and the camera is why it should work. ( https://developer.android.com/topic/instant-apps/faqs.html#available-permissions ) Thanks in advance.
source share