사운드 보드 응용 프로그램을 만들고 있는데 어떤 메뉴 항목을 클릭했는지에 따라 벨소리 또는 알림으로 사운드를 재생하려고합니다. 벨소리는 현재 벨소리 메뉴의 기본 벨소리로 표시되지만 전화가 오면 재생되지 않습니다. 무엇이 잘못 되었습니까? 내 코드는 다음과 같습니다.안드로이드에서 내 벨소리를 재생하려면 어떻게해야합니까?
public boolean saveas(int ressound,String file,String typesound){
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=file+".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, file);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
values.put(MediaStore.Audio.Media.ARTIST, "douchebag");
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);
//set ringtone
Uri ringtoneUri = Uri.parse(path+filename);
if(typesound=="ringtone")
RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, ringtoneUri);
return true;
}
오류가 있습니까? 당신이보고있는 행동은 무엇입니까? 또한 앱이 예상대로 작동하지 않을 경우 예외를 catch하면 로깅을 시도하십시오. – CrackerJack9