2012-03-18 75 views

回答

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); 

您可以onReceive(Context context, Intent intent)而不是this在上面的代碼中使用context