鬧鐘鬧不醒的可以自己去調(diào)整下,這個最是最基本的
站在用戶的角度思考問題,與客戶深入溝通,找到遂川網(wǎng)站設(shè)計與遂川網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站設(shè)計、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請、虛擬主機(jī)、企業(yè)郵箱。業(yè)務(wù)覆蓋遂川地區(qū)。MainActivity
public class MainActivity extends AppCompatActivity { private AlarmManager alarmManager; private PendingIntent pendingIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //獲取鬧鐘管理者 alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); } public void setAlarmOne(View view) { //獲取當(dāng)前系統(tǒng)時間 Calendar calendar = Calendar.getInstance(); int huor = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); //1 彈出時間對話框 TimePickerDialog timePickerDialog = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int i, int i1) { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, i); c.set(Calendar.MINUTE, i1); //2確定好選擇的時間 //3設(shè)置鬧鐘 //4當(dāng)時間一到,將執(zhí)行的響應(yīng) Intent intent=new Intent(); intent.setAction("com.zking.risk_android_alarn_notification.RING"); pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0x101,intent,0); alarmManager.set(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(), pendingIntent); } }, huor, minute, true); timePickerDialog.show(); } public void setAlarmCycle(View view) { //獲取當(dāng)前系統(tǒng)時間 Calendar calendar=Calendar.getInstance(); int hour=calendar.get(Calendar.HOUR_OF_DAY); int minute=calendar.get(Calendar.MINUTE); //01.彈出時間對話框 TimePickerDialog timePickerDialog=new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int i, int i1) { Calendar c=Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY,i); c.set(Calendar.MINUTE,i1); //02.確定好選擇的時間 //03.設(shè)置鬧鐘 //04.當(dāng)之間一到,將執(zhí)行的響應(yīng) Intent intent=new Intent(); intent.setAction("com.zking.risk_android_alarn_notification.RING"); pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0x102,intent,0); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),5000, pendingIntent); } },hour,minute,true); timePickerDialog.show(); } public void cancelAlarmCycle(View view){ alarmManager.cancel(pendingIntent); } }