Skip to content Skip to sidebar Skip to footer

How To Save Picture In Instant App

how to save picture in instant app Copy

Any other permission will need the installed version of your app.

That means that you cannot read or write from the public storage. However you can access public content provider exposed to instant app, such as contact pickers or photopickers.

Source: Official FAQ here

Solution 2:

apply this code on your camera activies to get permissions

takephoto.setOnClickListener(newView.OnClickListener() {
        @OverridepublicvoidonClick(View view) {
            if (hasTakePermissions(getApplicationContext(), PERMISSIONS)) {
                takePicture();
            } else {
                ActivityCompat.requestPermissions(HomeActivity.this, PERMISSIONS, PERMISSION_ALL);
            }
        }
    });

@OverridepublicvoidonRequestPermissionsResult(int requestCode, @NonNullString[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        caseREQUEST_WRITE_PERMISSION:
            if (hasPermissions(getApplicationContext(), PERMISSIONS)) {
                takePicture();
            } else {
                ActivityCompat.requestPermissions(HomeActivity.this, PERMISSIONS, PERMISSION_ALL);
            }
    }
}
    publicstaticbooleanhasTakePermissions(Context context, String... permissions) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {

        for (String permission : permissions) {
            if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
                returnfalse;
            }
        }
    }
    returntrue;
}

Solution 3:

I'm late for the response, hopefully this will help someone

As mentioned, WRITE_EXTERNAL_STORAGE has Protection level: dangerous, therefore you can't use it. However, you can use Cache to save your images.

valoutDirectory= File(activity?.cacheDir, "image.jpg")

Word of caution: Use it wisely, as running into an OOM would be inevitable if there are multiples images.

Post a Comment for "How To Save Picture In Instant App"