All resources are mapped to integers. You want to get the integer value R.drawable.missing_album_art, and then add this to the rest of the line of your path. i.e.,
Uri uri = Uri.parse("android.resource://android.aberplayer/" + R.drawable.missing_album_art);
... that is, if you really need Uri. You can usually use an image resource as follows:
view.setImageResource(R.drawable.missing_album_art);
If you want to read the resource in a file, this is one way to do this (it writes the file to the application directory (for example, / data / data / packagename) with the name "filename"):
private File resToFile(int resourceID, String filename) { File file = getApplicationContext().getFileStreamPath(filename); if(file.exists()) { return file; } InputStream is; FileOutputStream fos; try { is = getResources().openRawResource(resourceID); byte[] buffer = new byte[is.available()]; is.read(buffer); fos = openFileOutput(filename, MODE_PRIVATE); fos.write(buffer); fos.close(); is.close(); } catch (IOException e) { e.printStackTrace(); } return file; }
source share