0
아마도 매우 간단한 해결책 일 것입니다 만 지금까지 경험이 거의 없습니다. Android 2.2 (mnt/sdcard)와 이전 버전 (/ sdcard)에서 모두 작동하려면 다음을 변경하십시오.Android : SD 카드 저장 기능은 안드로이드 전후에 모두 작동합니다 2.2
미리 감사드립니다.
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()
를하고있다;문자열 경로 = pathDir + "/ media/audio/notifications /"; String filename = "sound1"+ ". ogg";
답장을 보내 주셔서 감사합니다. 내 무지를 용서해주십시오. 어떻게 상기에 내포합니까? – Aaron
신경 쓰지 마라, 나는 생각한다. 이것이 잘못된 경우 어떻게하면 더 잘 할 수 있는지 알려주십시오. 대단히 감사합니다 !!! – Aaron