私は、ユーザーがボタンを長押しして着信音としてサウンドを保存できるAndroidアプリケーションに取り組んでいます。私はそうするために以下のコードを使用しています。このコードは現在、使用する着信音のリストにファイルを保存するように機能しますが、サウンドをデフォルトの着信音として自動的に設定することはありません。私はあちこちを検索しましたが、デフォルト/アクティブな着信音としてサウンドを保存するための明確なガイドを見つけることができませんでした。
今のところ、ユーザーはボタンを長押ししてから、[メニュー]>[サウンド]>[電話の着信音]メニューに移動してリストから選択できますが、単純に設定することができるとわかっている場合は、少し不便に思えます。すぐにアクティブな着信音。
私が欠けているものについての洞察はありますか?とても有難い!
public boolean saveas(int ressound){
byte[] buffer=null;
InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
int size=0;
try {
size = fIn.available();
buffer = new byte[size];
fIn.read(buffer);
fIn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
return false;
}
String path="/sdcard/media/audio/ringtones/";
String filename="ADTone"+".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, "AD Ringtone");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
values.put(MediaStore.Audio.Media.ARTIST, "adtone ");
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;
}