learningtech
learningtech

Reputation: 33673

Why can't I get a resource file in my android project?

I have the following three lines of code in my project:

String filePathString = "android.resource://"+this.getPackageName()+"/res/raw/oldphone_mono.wav";
File f = new File(filePathString);
if(f.exists()) {/* do something */}

At runtime, the filePathString has the value android.resource://com.johntestapp/res/raw/oldphone_mono.wav . In my project, I can see that I have the file oldphone_mono.wav in my /res/raw/ directory. But for some reason, f.exists() still evaluates to false. What's wrong with the way i'm declaring the path to my wav file?

Upvotes: 0

Views: 121

Answers (1)

user692168
user692168

Reputation:

Do InputStream inputStream = getResources().openRawResource(R.raw.oldphone_mono); instead.

Upvotes: 2

Related Questions