I'd like to show a png in the built-in image viewer.
Here is my code:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "image/png");
startActivity(intent);
It displays a msgbox with a list which contains more than 10 different applications that can display the image.
How to limit the msgbox to two or three applications (the most significant if
possible)?
I belive you cant do that, the point of the Intent is to let the user have to freedom to decide what to use to open it.
Related
I use following code to open an image in the gallery:
public void onItemClicked(PictureItem item){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri imageUri = FileProvider.getUriForFile(getApplicationContext(), "myapp.fileprovider", new File(item.uri.getPath()));
intent.setDataAndType(imageUri, "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
This shows my photo in the gallery, but in a 'read-only' mode. I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Which action do I have to use for that? I do not want to use pick, just normal view with the option to delete. I tried ACTION_EDIT but it's not supported (and not quite the right choice neither ...).
I use following code to open an image in the gallery
First, there are hundreds, if not thousands, of "gallery" apps available for Android.
Second, your code simply asks to view an image (with a broken Intent due to your wildcard MIME type). There is no requirement for the app that responds to be a "gallery" app.
I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Then implement that yourself, in your own app, and get rid of the ACTION_VIEW Intent.
Which action do I have to use for that?
There is no Intent action that says "please display this image, but only if you are a gallery app, and, oh, by the way, you must offer a delete option", which appears to be what you want.
I've a sequence of image paths on my sd card and I display them on a list.
I'd like to associate the onitemclick to image visualization and, rather than create my own activity, I wanted to know if there was an intent which, given an image path, displays it.
This solution assumes that you have the path of your image:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "image/png");
startActivity(intent);
Currently I have the following:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(mediaLoc)), "image/" + type);
context.startActivity(intent);
This was because the app used to download images from urls and saved them into the sdcard before viewing. But now I want to change the implementation to show the image from a url in the default image viewer when ACTION_VIEW is called and give them the option to save. Is this possible with ACTION_VIEW? I'm asking because I wish to use the default image viewer in the phone as it has already handled the zoom functions.
You would have to make a custom action_view for it.
I'm running 2.3 on a Nexus S (but writing code against 2.2), and it takes forever for an image to display in the default cooliris gallery. This is how I am attempting to display an image:
Uri imageIdentifier = getImageUriOnFilesystem();
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(imageIdentifier, "image/jpeg");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Activity.this.startActivity(intent);
In the end, it takes 5-10 seconds for the gallery to go from a black screen to showing my image which is absurdly long and makes me think I'm doing something wrong. Is there a better way to display an image in the gallery without requiring a different gallery be installed?
You can add new images to the media index as you acquire them, which may may reduce the startup time of the gallery application.
Intent i = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
i.setData(imageIdentifier));
sendBroadcast(i);
We can view an image with code:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("/sdcard/test.jpg");
intent.setDataAndType(Uri.fromFile(file), "image/*");
startActivity(intent);
What if we have some images? How can we put the extras to let the viewer know we have
/sdcard/a.jpg, /sdcard/b.jpg, /sdcard/c.jpg ?
I hope to do this in a time because starting an activity is very expensive.
can any one help me? Thanks!
You can't.
The whole system of intents and uris is to either do an action on one item, or do an action on all items. See http://developer.android.com/reference/android/content/Intent.html and search for "content://contacts/people/1" and "content://contacts/people/" Have you tried looking for the intent that would let the viewer show all images in "/sdcard/". Even better is to plug into the content provider of that native viewer.
http://developer.android.com/reference/java/io/File.html#exists%28%29