Android 安卓闹钟设置音量和铃声
我需要添加一个预设铃声和最大音量的闹钟Android 安卓闹钟设置音量和铃声,android,android-alarms,Android,Android Alarms,我需要添加一个预设铃声和最大音量的闹钟 但我不明白如何将此信息传递给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
但我不明白如何将此信息传递给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我想这对你有用
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_ALARM);
我想这对你有用
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_ALARM);
对不起,我不明白这怎么有用。。。。我使用的不是mediaplayer,而是闹钟……对不起,我不明白这是怎么有用的。。。。我用的不是mediaplayer而是闹钟。。。