any sbstitute way to fetch file path of stored pictures - android

This path is fine for some devices to fetch path of captured images but this not works for all devices because some does not contain dcim file it self. So i need to fetch path dynamically to all devices is there any way to do this using any api . thanks.
File path = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM
+ "/Camera");

You can query the content resolver using managedQuery. It will return a cursor through which u can access the image/video/sound files.

Related

Retreive the Content location of a picture stored in games persisteant data path

I am having a little issue when trying to pass an image uri to androids gallery.
The code for openign the image in the gallery is working as it comes up with a selection box to choose the application to open the uri.
The uri that I am using is content://Android/data/com.littleminimonsters.match/files/LMM_Ghost_20181130.png
Is that the correct way to format a content uri? the file is stored in that location but on the SDCard (Android/data/com....)
I've tried just using the full path too with no luck (content://storage/emulated/0/Android/data/com...)
Any ideas on what the content uri should be?

Why cant i load the image in picasso?

The actual code is very simple like this but doesnt works!!
File f = new File("file://E:/test.jpeg");
Picasso.with(this).load(f).
into(avatar);
File f = new File("file://E:/test.jpeg");
First, Android does not have drive letters, let alone an E: drive. That is not a valid filesystem path to any file on any Android device.
Second, the File constructor takes a filesystem path, not a Uri with a scheme (e.g., file://).
Its important to know that the file you are accessing has to be on your DEVICE and NOT from your computer. There is no such directory as a E: drive on phones.
You have a few options. Store the image online, and load it with Picasso (the easiest).
Picasso.with(getActivity())
.load("http://www.image_url.com/image.png")
.into(avatar);
Or, you can get the file path of an image, and then use that with picasso.
File file = new File("path-to-image/image.png")
Picasso.with(getActivity()).load(file).into(avatar);
How do you get the path-to-image of an image on your device?
You can follow this http://www.limbaniandroid.com/2014/03/how-to-get-absolute-path-when-select.html

Can't find file downloaded by download manager in android

I'm trying to download a file to directory that can vary based on whichever directory the user chooses. I store the current directory in a file object and now attempting to download the file. The file downloads, but it doesn't download the specified directory. So, what can I do to get the file in the directory selected.
// Getting path to store the file
String path = root.getAbsolutePath();
path += curr.getName();
request.setDestinationInExternalPublicDir(path, new File(url).getName());
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
The String named url, that is being passed to the File constructor, contains a URL. Just using that to retrieve that name of the file.
UPDATE:
I just found the file. Its in the phone not the sd card. It was in this folder, storage\emulated\00. Not sure why? Also, the absolute path that I'm getting is storage\emulated\0.
So, I figured out that the path returned is always storage\emulated\0 for the call getExternalStorageDirectory().getPath()) to the Environment. Which is what I using to the get the initial directory. So for instance if I navigated through the folders to the Downloads folder the path would be storage\emulated\0\Download. When I was downloading the file though instead of going to the actual downloads folder it would go to, or create, the downloads folder in the emulated folder in the storage folder. To resolve this I found the index of the zero in the path, added 1, and got the substring using that. After that it worked. Also I had to do this in another method where I navigate through the directory. As a parameter I pass in the file and then within the method I get the substring. Within the method that I use to download the file I get storage\emulated\0 no matter what. Not sure why it does this. If anyone could explain this it would be greatly appreciated.
Does root.getAbsolutePath() return a string with a path separator character at the end?
If not, then you might be doing something like bin/usr/var/appfilename.ext instead of bin/usr/var/app/filename.ext, because you're concatenating it straight into name of the file.
I still had this issue on Android 7. In my case, the file would not show up until I restart the device. This a known issue: https://issuetracker.google.com/issues/36956498
Source: https://stackoverflow.com/a/20413888/2552811

Cannot resolve image path using content provider in BB10 Android Runtume

I have ported my android application to BB10. In my application there is one feature where we can send email with image attachment. In android it works fine but in BB10 image is not attached to mail.
I implement custom content provider for android. So when I select any image it will give the path as "content://providername/mail/attachment/image name" but it doesn't work on BB10.
In the BB10 relative path like "content: //" is not working. BB10 only works on Absolute path.
Code sample:
Path of image: content://com.abc.provider.local.file/mail/attachment/1.jpg
Uri.parse(LocalFileProvider.MAIL_FILE_URI + picture.getFileName()
In above code
LocalFileProvider.MaIL_FILE_URL = content://com.aba.provider.local.file/mail/attachment
picture.getFileName() = 1.jpg
Now how to convert this path to Absolute path Example like : file://
BB10 has the bar-descriptor.xml file that contains info about your app. One of the settings is the location of assets. For example - if you want to include a directory called "assets" with your package - you would have the followinf xml entry in your ..bar.xml file
<asset path="assets">assets</asset>
This assumes that you have the folder called "assets" in the root of your project.
Now you can place additional folders and files under "assets" and you can get at it by using the following URI
asset:///graphics/myimage.png
This would be an image located under /assets/graphics/myimage.png
Hope this helps.

Android: getting thumbnails from specific location on sd card

AFAIK accessing thumbnails for images via MediaStore.Images.Thumbnails would generate thumbnails at first attempt, and that's what I need to perform against specific location on sd card.
The question is how to make valid URI to content under specific folder?
All answers I can find use just MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI as uri to make managedQuery. And result of it is Cursor that points to all sdcard images, while none examples can be found on how to access only specific folder.
Maybe you could just list files in the directory and parse them to get thumbnails without using content provider. You can use inSampleSize option to get small bitmap not the complete image Strange out of memory issue while loading an image to a Bitmap object.
may be is to late, but for some one will be helpfull
Mihai Fonoage said...
Use something like
File imagesDir = new File(Environment.getExternalStorageDirectory().toString() + "/pathToDirectory");
File[] imageList = imagesDir.listFiles();
for (File imagePath : imageList) {
bitmap = BitmapFactory.decodeStream(imagePath.toURL().openStream());}
Here you have some great tutorial.

Categories

Resources