2012-03-05 22 views

答えて

0

問題はここに

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

Environment.getExternalStorageDirectory()では、とにかく着信音を保存するためにいくつかの他のフォルダ名を使用して、あなたに/ SDカードのパスを返します。代わりに/ SDカード/メディア、それはその後、/SDCard/yourPackage/media/

として解釈されるように

のように/ yourPackage /メディアは、それがここに

+0

はい、 'Environment.getExternalStorageDirectory()は'とにかくので、 '文字列のパス= Environment.getExternalStorageDirectory()を使用して、代わりに –

+0

をその部分をスキップ/ SDカードのパスあなたを返します。ある、getPath()+"/yourPackage/COM。 ring/media "; ' –

+0

動作しません。/media/ringtone/ –

0

OK役立ちます私は現在、データを格納するための私のアプリケーションで使用するサンプル・コードを願って私のSDCardに見て、これを使ってみてください。

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 
関連する問題