如何获取 res.drawable 文件夹的路径以复制文件?

Dir*_*don 3 java android

我正在编写我的应用程序AndroidStudio,我的文件drawable/gifs夹中有 gif 文件,我希望MediaStore.Images.Media在单击按钮后将该文件复制到文件夹中。

目前,即使使用发布的一些答案,我也无法获得我的 gif 路径。我尝试使用的路径是 android.resource://com.example.bartoszwolski.cluainkeyboard/drawable/gifs/my.gif

Leo*_*huk 5

只需使用 Uri:

Uri fileUri = Uri.parse("android.resource://your_packagename/" + R.drawable.your_image_id);
Run Code Online (Sandbox Code Playgroud)

和:

new File(fileUri.getPath());
Run Code Online (Sandbox Code Playgroud)