1
我想通過程序編碼設置手機的alram。我有一個按鈕,通過點擊DatePicker來&也時間選擇器。我想在這裏設置的時間應該在手機alaram中設置。我怎樣才能做到這一點 。請給我答案。謝謝android如何通過代碼設置手機報警
我想通過程序編碼設置手機的alram。我有一個按鈕,通過點擊DatePicker來&也時間選擇器。我想在這裏設置的時間應該在手機alaram中設置。我怎樣才能做到這一點 。請給我答案。謝謝android如何通過代碼設置手機報警
請試試這個....
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, 0);
cal.set(Calendar.HOUR_OF_DAY, 9);
cal.set(Calendar.MINUTE, 01);
cal.set(Calendar.SECOND, 0);
Intent intent = new Intent(Alarm.this, Alarm1.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 1234567, intent, 0);
PendingIntent sende2 = PendingIntent.getBroadcast(this, 123123, intent, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sende2);
Intent intent1 = new Intent(Alarm.this, Alarm1.class);
PendingIntent sender1 = PendingIntent.getBroadcast(this, 1234567, intent1, 0);
AlarmManager am1 = (AlarmManager) getSystemService(ALARM_SERVICE);
am1.cancel(sender1);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Alarm a = new Alarm();
a.setAlarm();
b1.setText(prod);
}
});