我有代码打开存储在资源文件夹内的raw文件夹中的文件。 (FileNotFoundException保持关闭的例外,无法找出原因。
码
package besttech.rtstarwars;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import android.os.Bundle;
public class RingtunesstarwarsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
testringtone();
}
void testringtone()
{
File newSoundFile = new File("/sdcard/", "myringtone.oog");
Uri mUri = Uri.parse("android.resource://besttech.rtstarwars/R.raw.blasters.mp3");
ContentResolver mCr = getContentResolver();
AssetFileDescriptor soundFile;
try {
soundFile= mCr.openAssetFileDescriptor(mUri, "r");
} catch (FileNotFoundException e) {
// CODE KEEPS GOING HERE
soundFile=null;
}
答案 0 :(得分:0)
将您的URI代码更改为:
String strUri = "android.resource://"+
RingtunesstarwarsActivity.this.getPackageName()+ "/" + "raw/blasters";
Uri mUri = Uri.parse(strUri);