0

こんにちは、音を着信音または通知として保存する際に問題があります。セットの Toast を取得し続けます - 失敗しました - SDCard を確認してください

間違いはどこですか?

コード: http://pastebin.com/in5ckvk0

4

2 に答える 2

0

これが、SDカードにデータを保存するためのアプリケーションで現在使用しているサンプルコードです。これを見て、使用してみてください。

    File newSoundFile;
    ContentResolver mCr;

    Log.e("check this tag","path for SDCard:"+Environment.getExternalStorageDirectory().getAbsolutePath());

    //storing at:  /mnt/sdcard/media 
    File directoryStructure=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Halloween");


    //if directory doesn't exist create a directory if that fails too return false
    if(!(directoryStructure.exists())){
        if(!(directoryStructure.mkdirs())){
            return false;
        }
    }

    /*for(int allRing=0;allRing<ringId.length;allRing++)*/{

        newSoundFile     = new File(directoryStructure, "/"+HalloweenWallpaper.longPressSelected+".mp3");
        Uri mUri = Uri.parse("android.resource://"+getApplication().getPackageName()+"/"+ringId[HalloweenWallpaper.longPressSelected]);
        mCr = HalloweenWallpaper.this.getContentResolver();
        AssetFileDescriptor soundFile;
        try {
            soundFile= mCr.openAssetFileDescriptor(mUri, "r");
        } catch (FileNotFoundException e) {
            soundFile=null;
            Log.e("first check", "here --"+e.getMessage());
            return false;
        }

        try {
            byte[] readData = new byte[1024];
            FileInputStream fis = soundFile.createInputStream();
            FileOutputStream fos = new FileOutputStream(newSoundFile);
            int i = fis.read(readData);

            while (i != -1) {
                fos.write(readData, 0, i);
                i = fis.read(readData);
            }

            fos.close();
        } catch (IOException io) {
            Log.e("Second Check", "--"+io.getMessage());
            return false;
        }       

    }


    //STORES SUCCESFULLY 
于 2012-03-05T16:03:37.713 に答える
0

問題はここにあります

  String path=Environment.getExternalStorageDirectory().getPath()+"/sdcard/media/ringtone/";

Environment.getExternalStorageDirectory() とにかく/ SDCardパスを返しますが、他のフォルダ名を使用して着信音を保存します。/sdcard/media の代わりに /yourPackage/media のように

それは次のように解釈されます。/SDCard/yourPackage/media/

それが役に立てば幸い

于 2012-03-05T09:43:28.150 に答える