简体   繁体   中英

Android, Java, Choose image from gallery. Store link and open later

I want to select one or more images in application ( Activity ) and use them in Service . I receive Uri s using Intent like this:

Intent galleryIntent = new Intent(Intent.ACTION_PICK,
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryIntent, "Select Picture"), RESULT_LOAD_IMG);

Uri s I get work but only for some time. From what I understand Uri s are temporary. In my case I need permanent links to image files.

Is there a simple way to receive usable (in this situation) link to an image file?

Is there a simple way to receive usable (in this situation) link to an image file?

Copy the image to your app's internal storage.

On Android 4.4+, you could use ACTION_OPEN_DOCUMENT and the Storage Access Framework, instead of ACTION_GET_CONTENT (or, worse, ACTION_PICK ). With the Storage Access Framework, you can request to take persistent permissions for the Uri , which increases the odds that you will be able to access the content in the future. However, even in that case, the user can always get rid of the image in question, eliminating your access to it.

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