Is it possible to get the path of an image in string form in android like
res/drawable/image.png
Or is their any other way for getting string path of an image that is placed in drawable.
No, it is not.
Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
e.g. will give you the default launcher icon. It is not possible to get the exact path for an image , that is stored in drawable.
Why not? When you compile your app to an *.apk file, all resources (ok, except from them in /raw) are compiled as well. You can only acces them, using their R. id.
Solution? Not really, you could copy them to a location on the sd card for example. Now you know the location :)
its not possible to get path of drawable image directly , but you can get this by storing it in internal memory or sdcard of device.For this i have written blog.. check out the link
here
i am sure it will help you.
Related
My ImageButton in my app is very tiny and cut off. I realized this could be because the image was in the drawable folder instead of the mitmap folders. So, I copied the images from the drawable folder, and pasted them in mitmap folders. Now, should I go about deleting the image from the drawable folder? I get the following saying it is not safe:
I know how to access the images, but should I delete them from the drawable folder now that I have already moved them to the mitmaps? If I do a delete anyway, will I need to alter my code to access the mitmap image? What is safest to do?
Here is an image of my mitmaps:
Thanks for the expert advice,
Rich
"Not safe" in this context just means that it's still being used somewhere. If you delete it, the current usage will fail to compile, and you'll be easily able to find and alter it to point at the new location.
You can safely delete this image, in Android Studio if you are using this image or else the file will be open at some place, you can get this error actually, so try deleting this image will safely remove the only selected image into your workspace. So hassle free to delete it.
After deleting your image, clear your project and run it, it works fine.
The mipmap folder is used for image that are very small and should be used in the action bar, and other menus. If you find your image too tiny, it just will be worst if you put it in the mipmap folder. If it's tiny although the image is in the drawable folder, maybe the image has a very small dimension or your imageview is too small.
I'm looking to have a user select an image from the gallery, and have this file saved as a permanent drawable resource when they open the app at a later time. Is this possible?
I mean as an object in the actual drawable folder.
No, it's not possible. "The drawable folder" doesn't exist as a file system folder at runtime - it's part of your (read-only) binary .apk file.
You could instead save the image at internal folder and/or define a preference string.
Check this old answer https://stackoverflow.com/a/3374138/4618976
I am using HorizontalScrollView in order to create some Gallery-like option and right now I am getting the images from an folder in the external drive. But I figured that I don't need, also shouldn't do that since the images I wanted to show is predetermined images. So I will simply change the directory to the drawable folder but I am not sure which path to go. So right now I am getting the directory with this:
String path1= Environment.getExternalStorageDirectory().getAbsolutePath();
I found two more methods for directory retrieval but I am not sure which one to use.
String path2 = Environment.getDataDirectory().getAbsolutePath();
String path3= Environment.getRootDirectory().getAbsolutePath();
First one returns "/mnt/sdcard", second returns "/data", third one "/system".
Which one should I use in order to reach /drawable folder inside this way?
Which one should I use in order to reach /drawable folder inside this way?
None of them. Those are all for files on the filesystem. Drawable resources are not files on the filesystem.
Use getResources().getDrawable() to retrieve a Drawable given its ID (e.g., R.drawable.foo).
I am working on quiz application. I stored the column data in the following form in sqlite database.
I am able to retrieve the question but now I need to retrieve the image of that particular question. I kept the images in drawable folder. But I need to change the i.e src="/test/image1.png" to src="/drawable/image1.png". If I change the path like the path of the
image in sqlite colum at then can I get the image which I kept in my drawable folder? Please help me regarding this...
Thanks in advance
I would insist that in database you can just give the name of the image and then you can get the image using getIdentifier,
getResources().getIdentifier(name,"drawable", getPackageName());
Where name will be the name of your image i.e - "image1"
It can be done like this aswell:
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
where this refers to the context of the actual activity.
getResources().getIdentifier(name,"drawable", getPackageName());
just name the src="image1.png"
and put the files in your assets folder images and html
On my application I have many pictures which I have grouped in folder under res/drawable. But Android dosen't let me access them trough "R". Is there a way to access those folders.
This is the Code im using for.
ImageView iv = new ImageView(conext);
iv.setImageResource(R.drawable.**smiley.666**);
I marked the part which I can't access.
Thx in Advance
safari
No, Android does not allow subfolders under /res/drawable: Can the Android drawable directory contain subdirectories?
You can however, add all image files under /drawable and then access them programmatically via:
int drawableID = context.getResources().getIdentifier("drawableName", "drawable", getPackageName());
iv.setImageResource(drawableID);
Where drawableName is a name of the drawable file, i.e. myimage if image file is myimage.jpg.
The code above will get image resource with id R.drawable.drawableName.
R.drawable.xxx is just a reference that the Android SDK generates in your R.java file. You are trying to make a sub-folder in your res-folder. The SDK can't generate a reference to any of your sub-folders, you have to put it in the predefined folders drawable-hdpi, -ldpi and -mdpi.
If you dont know how this works. I'll sum up. Android runs on a lot of different devices with a lot of different screen resolutions. With these three folders, you can have the same picture in three resolutions and depending on the device you are running your app on, one of these three folders will be used. You can read more here:
http://developer.android.com/guide/practices/screens_support.html
You can't create folders in res/drawable the system doesn't recognize those.
you need to save your image first and then make a xml for them so you can access it through R.your_pics
context.getResources().getDrawable(R.drawable.progressbar1);
Android - Open resource from #drawable String