我需要添加一个带预设铃声和最大音量的闹钟
但我不明白我如何将这些信息传递给AlarmClock ....
我在我的res / raw(在apk中)有铃声,我使用这段代码:
Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(AlarmClock.EXTRA_HOUR, oratimer);
i.putExtra(AlarmClock.EXTRA_MINUTES, minutitimer);
i.putExtra(AlarmClock.EXTRA_RINGTONE, saveSong(context, R.raw.song).toString());
i.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
context.startActivity(i);
这是saveSong函数:
public Uri saveSong(Context context, int song) {
byte[] buffer = null;
InputStream fIn = context.getResources().openRawResource(song);
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 null;
}
String path = Environment.getExternalStorageDirectory()+"/Ringtones/";
String filename = "song" + ".mp3";
boolean exists = (new File(path)).exists();
if (!exists) {
new File(path).mkdirs();
}
exists = (new File(path+filename)).exists();
if (!exists) {
FileOutputStream save;
try {
save = new FileOutputStream(path + filename);
save.write(buffer);
save.flush();
save.close();
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(new File(path + filename))));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
return null;
} catch (IOException e) {
// TODO Auto-generated catch block
return null;
}
}
return Uri.fromFile(new File(path+filename));
}
但警报是使用默认音量的默认铃声(如70%?)进行的 解决这个问题的任何提示? TNX
答案 0 :(得分:-1)
我认为这对你有用
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_ALARM);