in my app i let the user select an image from the gallery and had no problems doing this pre 4.2 but now when I select an image that is synced from my google+ account which
what I ended up doing to solve this is save the image locally and use the uri of that image anytime I need the image
@Override
public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent){
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
if(resultCode == Activity.RESULT_OK && requestCode == 1){
Uri selectedImage = imageReturnedIntent.getData();
new SaveImage().execute(selectedImage.toString());
}
}
public class SaveImage extends AsyncTask<String,Void,Void>{
@Override
protected Void doInBackground(String... params) {
String uri = params[0];
if(uri != null && !uri.equals("")){
ContextWrapper cw = new ContextWrapper(getActivity());
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
File mypath=new File(directory,String.valueOf(bowlerID)+"profile.jpg");
FileOutputStream fos = null;
InputStream input = null;
try {
fos = new FileOutputStream(mypath);
input = getActivity().getContentResolver().openInputStream(Uri.parse(uri));
Bitmap bitmap = BitmapFactory.decodeStream(input);
if(bitmap != null){
if(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos)){
ContentValues values = new ContentValues();
values.put(BowlersDB.PHOTO_URI, mypath.getAbsolutePath());
getActivity().getContentResolver().update(BowlersDB.CONTENT_URI, values,BowlersDB.ID+"="+bowlerID,null);
}
}
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
}
I had a similar problem implementing ACTION_SEND and ACTION_SEND_MULTIPLE in my app (also in Android 4.2.x). If I went to the gallery, selected one or more Picasa images, then chose "share", then chose my app from the picker, my app would throw the same SecurityException as above. Any attempt to use a query/load method from ContentResolver would throw.
I also tried adding the GALLERY_PROVIDER permission, but it didn't help (also, I looked in Instagram's manifest; It doesn't have this permission listed).
Eventually, on a whim, I took out android:launchMode="singleTask" from my entity, and low and behold, everything worked.
I have no idea why a single-task app would be barred from sharing in this way. Bug? Feature?