java 如何获取 res.drawable 文件夹的路径以复制文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30045988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get path to res.drawable folder to copy a file?
提问by Dirindon
I am writing my app in AndroidStudio
, I got gif file in my drawable/gifs
folder and I wish to copy that file to MediaStore.Images.Media
folder after clicking a button.
我正在编写我的应用程序AndroidStudio
,我的文件drawable/gifs
夹中有 gif 文件,我希望MediaStore.Images.Media
在单击按钮后将该文件复制到文件夹中。
Currently I can't get my gif path even when using some answers posted.
The path I've tried using is
android.resource://com.example.bartoszwolski.cluainkeyboard/drawable/gifs/my.gif
目前,即使使用发布的一些答案,我也无法获得我的 gif 路径。我尝试使用的路径是
android.resource://com.example.bartoszwolski.cluainkeyboard/drawable/gifs/my.gif
采纳答案by Leonid Veremchuk
Just use Uri:
只需使用 Uri:
Uri fileUri = Uri.parse("android.resource://your_packagename/" + R.drawable.your_image_id);
and:
和:
new File(fileUri.getPath());