0

我有代码可以打开存储在资源文件夹内的原始文件夹中的文件。(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;   
    }
4

1 回答 1

0

将您的 URI 代码更改为:

String strUri = "android.resource://"+ 
         RingtunesstarwarsActivity.this.getPackageName()+  "/" + "raw/blasters";
Uri mUri = Uri.parse(strUri);
于 2012-12-17T12:30:32.513 回答