On various answers on stackoverflow I have found a way to access an Android raw resource via file handle:
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.wikipedia);
File file = new File(uri.getPath());
Log.v("MyActivity", "File exists: " + file.exists());
I have also tried:
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/raw/wikipedia.png");
File file = new File(uri.getPath());
Log.v("MyActivity", "File exists: " + file.exists());
Tried hard coding the package name and/or using uri.toString() as well.
But I never get a file handle, the log always states:
V/MyActivity﹕ File exists: false
What am I doing wrong?
This is a blank application, I just copied any random file to the raw folder.
Why I need a file handle? Because in my application, I have a pretty big raw file that that I don't want to copy first via InputStream, but the library I am using requires a file handle.
0 comments:
Post a Comment