简体   繁体   中英

Android - how to open image in gallery with delete option

I use following code to open an image in the gallery:

public void onItemClicked(PictureItem item){
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);

    Uri imageUri = FileProvider.getUriForFile(getApplicationContext(), "myapp.fileprovider", new File(item.uri.getPath()));

    intent.setDataAndType(imageUri, "image/*");
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(intent);
}

This shows my photo in the gallery, but in a 'read-only' mode. I want to be able to delete the image from there, just as if I opened it directly in the gallery.

Which action do I have to use for that? I do not want to use pick, just normal view with the option to delete. I tried ACTION_EDIT but it's not supported (and not quite the right choice neither...).

I use following code to open an image in the gallery

First, there are hundreds, if not thousands, of "gallery" apps available for Android.

Second, your code simply asks to view an image (with a broken Intent due to your wildcard MIME type). There is no requirement for the app that responds to be a "gallery" app.

I want to be able to delete the image from there, just as if I opened it directly in the gallery.

Then implement that yourself, in your own app, and get rid of the ACTION_VIEW Intent .

Which action do I have to use for that?

There is no Intent action that says "please display this image, but only if you are a gallery app, and, oh, by the way, you must offer a delete option", which appears to be what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM