how to get file path of asset folder in android

﹥>﹥吖頭↗ 提交于 2019-12-20 12:11:04

问题


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?


回答1:


You could put your mp3 files at : res/raw folder.

MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.myringtone);
mediaPlayer.start();



回答2:


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.




回答3:


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();


来源:https://stackoverflow.com/questions/22906068/how-to-get-file-path-of-asset-folder-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!