我想在调用broadcastreceiver的onReceive()方法时启动闹钟。
答案 0 :(得分:0)
使用以下代码
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);
您可以在上面的代码中使用context
中的onReceive(Context context, Intent intent)
代替this
。