如何让资源文件夹中的android文件路径
问题描述:
我已经习惯了从Android应用程序的资源文件夹中的PNG图片传输到我的本地服务器上的Android应用程序。我需要获得图像的资源文件夹的路径,请参考下我的code,
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);
如果我用上面的code我有的文件未发现异常。因此,如何在资源文件夹图片路径?
If I use the above code I got "File not found exception". So how to take image path in asset folder?
答
尝试:
file:///android_asset/raw/sample/logout.png
如果你有一个背景下,你可以使用 context.getAssets()。打开(原始/采样/ logout.png)
来打开的InputStream
上的文件。
If you have a Context, you can use context.getAssets().open("raw/sample/logout.png")
to open an InputStream
on the file.