Purpose of the camera for instant applications

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.

+5
source share
3 answers

I am afraid that the problem does not come from resolution, but from how you start your activity.

Instant applications cannot actually run actions with explicit intentions, unless specific intentions were available to instant applications.

EDIT: Sorry, I already told you that you are trying to run an explicit intention. In fact, the new Intent (MediaStore.ACTION_IMAGE_CAPTURE) is implicit. Therefore, I do not understand why you have a security exception. Are you using the latest version of canary 4?

For the difference between explicit intent and implicit:

  • Explicit intent is specifically for another application or component

  • Implicit intent allows the system to choose which application should process the intent. that is, Intent intent = new Intent(ACTION_VIEW,Uri.parse("http://www.google.com");

+2
source

I do not think that capturing photos using the intent MediaStore.ACTION_IMAGE_CAPTURE will work at the moment, unfortunately. Even if the action can begin, it requires write access to the external storage in order to actually send the full image back, and the external storage is not available for instant applications (see restrictions ). FileProvider also does not support Instant Apps at the moment, if the capture intent can be written to the internal storage (I'm not sure what).

Android.permission.CAMERA resolution is supported, you just need to use camera2 API . There is sample code that you can try here .

+2
source

Regarding Google's Error Tracker , the fix will be part of android 8.1 Oreo . Unfortunately, this cannot be fixed through the GMS, however, we are sending a fix for our partners so that they can accept the fix even if they are not building the 8.1 database.

If any problem persists, inform the Google tracker , which they will open for verification.

0
source

Source: https://habr.com/ru/post/1269338/


All Articles