0
我想在調用broadcastreciever的onRecieve()方法時開始報警。如何在BroadcastReciever中觸發警報?
我想在調用broadcastreciever的onRecieve()方法時開始報警。如何在BroadcastReciever中觸發警報?
使用此代碼如下
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.clear();
cal.set(2012,2,8,18,16);
AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
// cal.add(Calendar.SECOND, 5);
alarmMgr.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
您可以onReceive(Context context, Intent intent)
而不是this
在上面的代碼中使用context
。