I have tried various methods to extract the absolute path of an image from a Uri. I have checked out google and found a snippet but that does not quite work. It returns a weird address to my file, logcat says file not found.
I would be glad if anyone could share a proper method or snippet that helps me get the actual address of the Uri/ selected Image.
I have tried various methods to extract the absolute path of an image from a Uri
A Uri is not necessarily a file, and so there is not necessarily an absolute path to an image.
I would be glad if anyone could share a proper method or snippet that helps me get the actual address of the Uri/ selected Image.
You don't. You use ContentResolver to access the file contents (openInputStream()), get the MIME type (getType()), etc.
Related
I have a problem finding out what is the real mime type of a file whose name and extension was changed. For example, the file "app.exe" renamed to "picture.png" or "document.pdf", how can I get that the real mime type is ".exe"?
Thanks for your help.
Regards,
Check this answer. The main idea - all files have their type inside themselves. It means that you can read first bites and use this information to identify filetype and manually add extension or do whatever you want.
In my app, I get a really long SVG path as a string. I need to convert this path to polygon or array of points (absolute coordinates).
All solutions I have found so far are based on Batik (I cannot use this in Android Studio), SVGPathElement (awt.svg also not applicable in android) or JavaScript libraries (Raphael etc.).
So my question is, is there any other possibility to use a function like getPointAtLength(x) to sample the path, or do I have to write programmatically a parser? I have searched for hours to find an answer, unfortunately unsuccessful.
Thank you in advance!
Solution:
path = createPathFromPathData(String pathStr)
path.approximate(error);
returns an array of absolute points
I'm going to get list of files/folders on Google Drive (using Android Google Drive SDK V2). I've found https://developers.google.com/drive/v2/reference/files/list method for this, but i can't see any isFile() or isFolder property or method for the file. How can i do it? I've found kind property but is this what i need?
How can i get full file path for the file on drive?
How can i check the file exists?
Take a look at mimeType. You could have found this easily by looking at the file.list output on the oauth playground since the mimetype contains the word "folder".
"mimeType": "application/vnd.google-apps.folder"
You could also add a q for (Query string) then you can have it return just the folders for you. Then for each folder query its contents. https://developers.google.com/drive/search-parameters
But it depends on what you are trying to do.
Compare the item's mimeType to application/vnd.google-apps.folder - this is the mimeType of a Folder in GDrive.
Every item has a parents property that holds an array of parent folder. I guess you'll have to "manually" browse them and their parents to construct the absolute path of an item. Note that an item might have multiple parent folders.
You can either provide a query parameter in your request that will make the server return only existing files (trashed = false) or check the file's labels after you have fetched the info for that file. Of course this might vary depending on your meaning of "existing"...
I need images to be sorted by folders. like drawable/Photos, drawable/items, drawable/photos. and put each folder to the registry or at least find way to get them out of there. all I want is something close to php like "../img/photos/photo0.jpg". is there way to do something like this. and folder with Images must contain in apk file.
possible solutions is make link in the R file but I didn't find how to do it, other solution is find command with logic like I will show you here:
ImageView img = (ImageView)CloningTable.findViewById(R.id.img);
String ImgPath = "com.test.test/img/img0.jpg";
img.setImageDrawable(Drawable.createFromPath(ImgPath));
OR
ImageView img = (ImageView)CloningTable.findViewById(R.id.img);
String ImgPath = "com.test.test/img/img0.jpg";
img.setImageResource(ImgPath);
please say me the best way to handle it. AND specify if it contain path how I can know path the file lies in.
File ImgFile = new File("test/test.jpg");
TextView testtext = (TextView)CloningTable.findViewById(R.id.testtext);
if (ImgFile.exists()) {
test.setImageBitmap(BitmapFactory.decodeFile(ImgFile.getPath()));
testtext.setText("asdasuidjasdk");
}
can any one say Why programm can't find file and file exist 100% = /?
filepath: Project> assets/test/test.jpg
found solution: Android Show image by path
It's hard to understand why you need to sort resources that will be static in your APK, but you should not access them directly using paths, but using the API for that purpose.
Take a look at the topics in the dev guide here:
http://developer.android.com/guide/topics/resources/accessing-resources.html
http://developer.android.com/guide/topics/resources/drawable-resource.html
Those will teach you how to access the resources. To create Bitmaps from them, the easiest way is to use the BitmapFactory class
Remember, you know which resources the APK has at building time, so you can work around it. If you want to work with Bitmaps created at runtime, then use the data storage methods instead.
In this case, you should put resources in assets folder, and you can access them by path!
So if you want to save the path string, the best way is creating a class, with 2 variants: 1 Bitmap to store data, and 1 String to store the path.
If not, just create a String array that you may access when you want.
In both case, you need to put the path into the Path String storage before you load the image.
Hope I understood your question.
EDIT: Final answer that meet your requirement:
There's no path for drawable, they are all converted into ID. If you put in asset folder, just call it by their name. For example, you have "Test.bmp" in asset folder, its path is "Test.bmp". If you have "SubTest.bmp" in "TestFolder" in asset folder, its path is "TestFolder/SubTest.bmp". Sorry for long time, I had to sleep, it was mid night at my time zone.
So I am working with URIs in Android to set ringtones for individual contacts. Problem is, the way the ringtone selector works is that it doesn't like something such as myringtone.mp3. Instead, it just wants myringtone. Weird, but I guess that's just how it goes. So I have a URI like file:///sdcard/tag/ringtones/ringtone.mp3. How would I get the URI to remove the extension so the ringtone manager uses it properly? The way ringtones are set are with this line:
values.put(ContactsContract.Contacts.CUSTOM_RINGTONE, uri.toString());
So the URI is in string form. Using substrings I should be able to do it, but I don't know how I'd write a method to remove the final 4 characters in a string. Can anyone give me some advice here?
Thanks!
For situations where you don't know what the extension may be or unknown length, try:
uri.toString().substring(0, uri.getString().lastIndexOf("."));
Have you tried?...
uri.toString().substring(0, uri.toString().length() - 4);