下面是代码
new TimePickerDialog(ChooseTiMingTime.this, 0, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Intent intent = new Intent(ChooseTiMingTime.this, AlarmTestActivity.class);
//设置响铃时间
Calendar calendar = Calendar.getInstance();
// //设置年月日
calendar.setTimeInMillis(System.currentTimeMillis());
//设置时分
calendar.set(Calendar.HOUR, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
//构造一个PendingIntent对象
PendingIntent pendingIntent = PendingIntent.getActivity(ChooseTiMingTime.this, 0, intent, 0);
//设置在规定的时间内启动组件
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
//闹铃设置成功提示
Toast.makeText(ChooseTiMingTime.this, "闹铃设置成功", Toast.LENGTH_SHORT).show();
}
}, currentCalendar.get(Calendar.HOUR_OF_DAY), currentCalendar.get(Calendar.MINUTE), false).show();
下面是简单的dialog的activity
//加载指定音乐
mediaPlayer = MediaPlayer.create(AlarmTestActivity.this, R.raw.alarm);
//设置循环播放
mediaPlayer.setLooping(true);
mediaPlayer.start();
//创建一个对话框
new AlertDialog.Builder(AlarmTestActivity.this).setTitle("闹钟").setMessage("闹钟响了,GO!GO!GO!倩楠,你要迟到了!!!!").setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//停止音乐
mediaPlayer.stop();
//释放资源
mediaPlayer.release();
//结束该Activity
finish();
}
}).show();