可能是一个非常简单的解决方案,但到目前为止我的经验很少。如何更改以下内容以适用于 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评论后我有这个并且它正在工作
文件路径目录 = Environment.getExternalStorageDirectory();
字符串路径=pathDir+"/media/audio/notifications/"; 字符串文件名="sound1"+".ogg";