Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get file path of asset folder in android

I have an Android application used to transfer the .png image from asset folder of Android application to my local server. I need to get the path of image in asset folder, pls refer my code below,

String stringPath = "android.resource//"+getPackageName()+"/raw/sample/logout.png";             
File f = new File(stringPath);

If I use the above code I got "File not found exception". So how to take image path in asset folder?

like image 922
sivanesan1 Avatar asked Apr 07 '14 07:04

sivanesan1


2 Answers

Try:

file:///android_asset/raw/sample/logout.png

If you have a Context, you can use context.getAssets().open("raw/sample/logout.png") to open an InputStream on the file.

like image 75
Ion Aalbers Avatar answered Sep 17 '22 05:09

Ion Aalbers


Assets and resources are accessible using file:///android_asset and file:///android_res.

 Uri path = Uri.parse("file:///android_asset/raw/sample/logout.png");

 String newPath = path.toString();
like image 40
Sanu Avatar answered Sep 21 '22 05:09

Sanu