Please not that this is not a duplicate. I have not found a working answer to this question that that does not involve copying the file to external storage first.
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
Other answers on stackoverflow suggest copying the file to external storage before accessing it, that's what I am doing right now. What why should I store a 37MB file twice in the system?
There has to be a way to package a large file in the APK and access it. Unfortunately the library I am using requires a file handle, so there is no way around that.
What am I doing wrong in the examples above? This is a blank application, I just copied any random file to the raw folder.