1

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.

michaelk
  • 1,987
  • 3
  • 14
  • 18

1 Answers1

0

This article may make sense to you.

http://judepereira.com/blog/how-to-get-a-file-object-of-an-android-raw-resource-using-reflection/

Jerome
  • 1,729
  • 1
  • 14
  • 39
  • Thanks for the comment. Basically he is just copying the file to external storage and then accesses it. That's what I am doing right now. But I don't want to store a 37MB file twice in the system just to access it. There has to be another way? – michaelk Jul 31 '14 at 07:35