Following up on this question, is there a way to start an intent in android without prompting the user for anything?
Right now, I am retrieving the image like this:
public void changeImage(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, getResources().getString(R.string.select_picture)),
PICK_IMAGE);
}
Then I store the Uri, and when necessary display the image (I actually resize it first, but that doesn't matter):
Uri _uri = Uri.parse(_path);
InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(_uri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap b = BitmapFactory.decodeStream(imageStream);
iv.setImageBitmap(b);
I would like to retrieve the image data given its Uri by "silently" invoking the intent so as to get the relevant permission. So I would need something like:
Edit:
I tried the setPackage()
method. This code has the following behavior:
If the ACTION_VIEW intent is used, the gallery opens and shows the specific image.
If the ACTION_GET_CONTENT intent is used, I get prompted to pick an image from the gallery, even though I supply the specific Uri.
>
Uri _uri = Uri.parse(_path);
InputStream imageStream = null;
Bitmap b = null;
try {
imageStream = getContentResolver().openInputStream(_uri);
b = BitmapFactory.decodeStream(imageStream);
ImageView iv = (ImageView) findViewById(R.id.playerImage);
iv.setImageBitmap(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
Intent dummyIntent = new Intent(Intent.ACTION_GET_CONTENT);
//Intent dummyIntent = new Intent(Intent.ACTION_VIEW);
dummyIntent.setDataAndType(_uri,"image/*");
dummyIntent.setPackage("com.google.android.gallery3d");
startActivityForResult(dummyIntent, PICK_IMAGE);
}
Any ideas?