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
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 have an image/pdf/docx/video as part of a listview item. I want to open them with appropriate applications in android. Currently only the video seem to open properly. Rest does not work. Can someone kindly help me !!!
Here is my code snippet I use from onItemClick in a ListView:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(itemPath), "*/*");
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
I tried :
intent.setDataAndType(Uri.parse(itemPath), "image/*");
for image files and
intent.setDataAndType(Uri.parse(itemPath), "application/pdf");
for pdf files too. But none work.
Thanks.
I use the following code to share a image, it's Ok if the image type is png.
But I'm very surprised that it's still OK if the the image type is jpeg. Why? Thanks!
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file://"+arrPath[i]);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
This is how the Intent system works.
http://developer.android.com/guide/components/intents-filters.html#iobjs
An Intent object is a bundle of information. It contains information of interest to the component that receives the intent (such as the action to be taken and the data to act on) plus information of interest to the Android system (such as the category of component that should handle the intent and instructions on how to launch a target activity).
The responsibility of actually dealing with the file is left with the applications that register to handle that kind of intent. At this stage it's not going to care/check whether the file is a jpg or a png.
You're basically saying "hey, sharing applications! I have a png for you!"
I'm not sure what exactly you are after but if you don't want jpgs to be shared you need to handle that in your code.
Right now I have:
Intent gallery = new Intent( ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI );
gallery.setDataAndType(Uri.parse("file:///sdcard/DCIM/"), "image/*");
startActivity(gallery);
What I'd like to accomplish is to only display images from the DCIM directory down, but instead I'm seeing every image on the device. I don't see any errors or warnings popping up for my process when I run this. I've tried splitting into setData and setType which predictably had the same effect.
Thanks in advance for any insight into what I'm missing.
Take a look at this answer by PiyushMishra
Built-in gallery in specific folder
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.