Gayan Dinuzhka Gayan Dinuzhka - 1 year ago 239
Android Question

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


Answer Source

If you app is insalled on sdcard try this code :

Bitmap bitMap = BitmapFactory.decodeResource(getResources(),;

File mFile1 = Environment.getExternalStorageDirectory();

String fileName ="img1.jpg";

File mFile2 = new File(mFile1,fileName);
try {
       FileOutputStream outStream;

       outStream = new FileOutputStream(mFile2);

       bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);



} catch (FileNotFoundException e) {
       // TODO Auto-generated catch block
} catch (IOException e) {
       // TODO Auto-generated catch block

String sdPath = mFile1.getAbsolutePath().toString()+"/"+fileName;

Log.i("hiya", "Your IMAGE ABSOLUTE PATH:-"+sdPath); 

File temp=new File(sdPath);

       Log.e("file","no image file at location :"+sdPath);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download