Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open an image in gallery using file path

i have an image file path stored in my database. Now using it i want to open images from SD Card in my gallery. How can i do that. I have seen methods from Uri and using this method but i am getting error

File file = new File(filename);
            Uri uri = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.setType("image/*");
            startActivity(intent); /** replace with your own uri */

How to fix it,

04-20 08:42:23.516: E/AndroidRuntime(16815): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/My%20App/image_umxto_1.jpg }

best regards

like image 549
Muhammad Umar Avatar asked Apr 20 '12 03:04

Muhammad Umar


People also ask

How do I get the file path of a picture?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

What is image file path?

A file path describes the location of a file in a web site's folder structure. File paths are used when linking to external files, like: Web pages. Images.

How do I open an image from path in flutter?

In Flutter, displaying an image can be done by using Image widget. Flutter provides a named constructor File. Image which can be used if the image source is from a file. Alternatively, you can also use FileImage .


2 Answers

Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(new File(filename)), "image/*");
            startActivity(intent);

Use this code and tell me

like image 61
Muhammad Umar Avatar answered Oct 17 '22 23:10

Muhammad Umar


You can also use the below code:::

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);
like image 42
Shankar Agarwal Avatar answered Oct 17 '22 22:10

Shankar Agarwal