Android Select photos from Gallery

Source: Internet
Author: User

Taking photos from the machine, starting with a code test on the Web, leads to a crash like this:
Java.lang.RuntimeException:Failure Delivering result
Java.lang.SecurityException:Permission denial:reading com.android.providers.media.MediaProvider URI content:// media/external/images/media/1909 from pid=29038, uid=10236
Requires Android.permission.READ_EXTERNAL_STORAGE, or granturipermission ()


Fortunately, we found a solution here.
http://developer.android.com/samples/StorageClient/src/com.example.android.storageclient/StorageClientFragment.html#l233

Use the Getbitmapfromuri method in the line:

        /**Create a Bitmap from the URI for that image and return it. *         * @paramURI The URI for the image to return. */        PrivateBitmap Getbitmapfromuri (Uri uri) {parcelfiledescriptor parcelfiledescriptor=NULL; Try{parcelfiledescriptor=getactivity (). Getcontentresolver (). Openfiledescriptor (URI,"R"); FileDescriptor FileDescriptor=Parcelfiledescriptor.getfiledescriptor (); Bitmap Image=Bitmapfactory.decodefiledescriptor (FileDescriptor);                Parcelfiledescriptor.close (); returnimage; } Catch(Exception e) {log.e (TAG,"Failed to load image.", E); return NULL; } finally {                Try {                    if(Parcelfiledescriptor! =NULL) {parcelfiledescriptor.close (); }                } Catch(IOException e) {e.printstacktrace (); LOG.E (TAG,"Error Closing Parcelfile Descriptor"); }            }        }

Android Select photos from Gallery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.