Any intents to show a single image with zooming/panning? - android

I have a png and a jpg image on disk. I'd like to use any built-in intent (if any are available) to view the image (just a single one at a time). Something like this:
Intent intent = new Intent();
intent.setImagePath("/blah/myimage.jpg");
startActivity(intent);
is there a built-in intent in android to do this, or do I have to write my own image viewing-activity? It would be cool if there was one that had panning/zooming as found in WebView,
Thanks

This should work.
Uri uri = Uri.fromFile("/blah/myimage.jpg");
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/jpg");
startActivity(intent);

Related

why does Uri.fromFile(new File(url)) work and Uri.parse(url) not in open pdf by intent?

The code below can open pdf file by intent and works well:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(url)), "application/pdf");
if(intent.resolveActivity(getPackageManager()) != null){
startActivity(intent);
}
but if I change Uri.fromFile(new File(url)) to Uri.parse(url), just like below, and it will fail to open pdf file. Why?
intent.setDataAndType(Uri.parse(url), "application/pdf");
I know the class type of instance that the two method return is different, but is this the key that the code above works?
By the way, the url is right and the file exists.
Uri is Type used to provide content to the ContentProvider. The uri is the path to a pdf file right? How would Uri.parse know that what you're passing it is a pdf and not just a url? This is why fromFile is needed.

When I am browsing a file using intents it's not going to File Manager?

When i click on the Browse button i have added below code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
It shows FileManager in some devices like Redmi,Asus,Micromax.But it is not showing in Samsung phones,it's not going to file manager
How to get FileManager in Samsung phones to select a file?
try this is working for me
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent , CHOOSE_FILE_REQUESTCODE);
for Samsung Devices
String manufactures = android.os.Build.MANUFACTURER;
if(manufactures.equalsIgnoreCase("samsung")){
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
}
Replace
Intent intent = new Intent(Intent.ACTION_VIEW);
as
Intent intent = new Intent(Intent.GET_CONTENT);
EDIT
#Hanuman i think that single solution that fits all models doesn't exist, all intents with "actions" have to be processed by choosers. If you use >= 4.4 devices, I recommend
Storage Access Framework

Automatically open Intent Chooser for the file Android

I want to open a file in android. What i want to do is if the file is of type Image then i want to open Intent Chooser which contains applications that can view the image, and if it is of video type, then open Intent Chooser with applications that can view videos. How can i achieve this?
I have found a solution. I am pasting it here so it may help other users.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(path);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = file.getName().substring(file.getName().lastIndexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
intent.setDataAndType(Uri.fromFile(file), type);
context.startActivity(intent);
You should decide and know whether the file is video or image. You may do it by looking at the extension of the files.
After that you can open videos like this:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(result), "video/*");
startActivity(intent);
and images like this:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(result), "image/*");
startActivity(intent);
Android system will open the Intent Chooser automatically.

how to launch photo gallery with search parameter in Android programatically

I am trying to programatically launch or open the photo gallery after passing a photo name search parameter.
I am new at this. I am thinking maybe intents can be used but not sure so I am wondering if anyone could please point me in the right direction. Preferably with some code examples.
Much thanks.
RE-EDIT
As requested, this is the code I have so far..
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// CAMERA_PIC_REQUEST = 2600;
cameraIntent = Intent.createChooser(intent,"Select Picture");
you can try follow code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(photoUri);
context.startActivity(intent);
I think this is what you mean, correct me if I'm wrong:
String nameOfPhotoToBeRetrieved = "myPhoto";
String WHERE = "TITLE ="+nameOfPhotoToBeRetrieved;
Then you can use the following line to deliver a result to your cursor/listener:
CursorLoader(context,content_uri,null,WHERE,null,null).deliverResult(myCursor);

How to fire up the stock Gallery app with an image url that's in sd card

I have an image on the sd card. I need to fire up the stock Gallery app from my app to show the image. I get a NullPointerException from the stock Gallery app.
Here is my code.
Intent i = new Intent(Intent.ACTION_VIEW);
i.setType("image/png");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(IMAGE_URL_ON_SD_CARD));
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Can anyone help me understand what I am doing wrong?
Thanks a lot.
Try like this..
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16")));
If above code do not work thn try like this
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*"); startActivity(intent);

Categories

Resources