0

おそらく非常に単純な解決策ですが、これまでの経験はほとんどありません。Android 2.2 (mnt/sdcard) と以前のバージョン (/sdcard) の両方で動作するように次を変更するにはどうすればよいですか。

前もって感謝します!

String path="/sdcard/media/audio/notifications/";      
String filename="sound1"+".ogg";        

boolean exists = (new File(path)).exists();
         if (!exists){new File(path).mkdirs();}          
FileOutputStream save;      
try {        save = new FileOutputStream(path+filename);          
save.write(buffer);          
save.flush();          
save.close();         } 
catch (FileNotFoundException e) {        
// TODO Auto-generated catch block          
return false;        } catch (IOException e) {       
// TODO Auto-generated catch block          
return false;      }      

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename)));        

File k = new File(path, filename);         

ContentValues values = new ContentValues();         
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());         
values.put(MediaStore.MediaColumns.TITLE, "sound1 Notification");         
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");         
values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");         
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);         
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);         
values.put(MediaStore.Audio.Media.IS_ALARM, true);         
values.put(MediaStore.Audio.Media.IS_MUSIC, false);           

//Insert it into the database      
this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);       
return true;      }

//user432209のコメントの後、私はこれを持っており、動作しています

ファイル pathDir = Environment.getExternalStorageDirectory();

文字列 path=pathDir+"/media/audio/notifications/"; 文字列ファイル名="sound1"+".ogg";

4

1 に答える 1

1

おそらく、SD カードに直接保存したくないでしょう。保存する場所を「電話に尋ねる」ことをお勧めします。

File externalDirectory = Environment.getExternalStorageDirectory();
于 2011-01-24T03:24:17.537 に答える