为什么可以';我不能在我的android项目中获得一个资源文件吗?
我的项目中有以下三行代码:为什么可以';我不能在我的android项目中获得一个资源文件吗?,android,Android,我的项目中有以下三行代码: String filePathString = "android.resource://"+this.getPackageName()+"/res/raw/oldphone_mono.wav"; File f = new File(filePathString); if(f.exists()) {/* do something */} 在运行时,filePathString的值为android。resource://com.johntestapp/res/raw/o
String filePathString = "android.resource://"+this.getPackageName()+"/res/raw/oldphone_mono.wav";
File f = new File(filePathString);
if(f.exists()) {/* do something */}
在运行时,filePathString的值为
android。resource://com.johntestapp/res/raw/oldphone_mono.wav
。在我的项目中,我可以看到我的/res/raw/目录中有oldphone_mono.wav文件。但由于某些原因,f.exists()的计算结果仍然为false。我声明wav文件路径的方式有什么问题?DoInputStream InputStream=getResources()代码>取而代之。试试myActivity.getResources().openRawResource(R.raw.oldphone\u mono)
但是我想最终做一个MediaPlayer p=newmediaplayer();p、 setDataSource(这个,Uri.parse(filePathString))代码>。有没有一种方法可以将inputStream转换为filePathString?在这种情况下,您需要的是MediaPlayer mp=MediaPlayer.create(这个,R.raw.oldphone\u mono)代码>