Get Absolute Path Of Android Drawable Image
I need to get the absolute path or the File object of my drawable image in android application. Is there any way to do this? Drawable is as following context.getResources().getDraw
Solution 1:
If you app is insalled on sdcard try this code :
BitmapbitMap= BitmapFactory.decodeResource(getResources(),R.id.img1);
FilemFile1= Environment.getExternalStorageDirectory();
StringfileName="img1.jpg";
FilemFile2=newFile(mFile1,fileName);
try {
FileOutputStream outStream;
outStream = newFileOutputStream(mFile2);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringsdPath= mFile1.getAbsolutePath().toString()+"/"+fileName;
Log.i("hiya", "Your IMAGE ABSOLUTE PATH:-"+sdPath);
File temp=newFile(sdPath);
if(!temp.exists()){
Log.e("file","no image file at location :"+sdPath);
}
Solution 2:
Uripath= Uri.parse("android.resource://com.nikhil.material/" + R.drawable.image);
OR
UriotherPath= Uri.parse("android.resource://com.nikhil.material/drawable/image");
OR
Uripath= Uri.parse("android.resource://"+BuildConfig.APPLICATION_ID+"/" + R.drawable.image);
Solution 3:
drawable resources are added to binary at run time therefore cannot be accessed by path. you can decode and use drawables instead.
If you need resources you can access at runtime by path, try using assets folder instead.
Hope this is helpful
Post a Comment for "Get Absolute Path Of Android Drawable Image"