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