0
我正嘗試在我的應用程序中創建每週提醒。爲此,我使用AlarmManager。 下面是代碼生成報警在Android應用程序中創建提醒
pendingIntent = PendingIntent.getBroadcast(SettingsActivity.this, 1234567, new Intent(SettingsActivity.this, WeeklyReminder.class), 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 30);
long updateFreq = 30*1000;//24*60*60*1000;
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), updateFreq, pendingIntent);
這是一個擴展廣播
public class WeeklyReminder extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
try
{
System.out.println("Alarm Initiated");
Toast.makeText(context, "Recieved Alarm", Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}
在AndroidManifest.xml我有標籤
<receiver android:name="WeeklyReminder">
我想在此之前進入每週一次的餘類該提醒即使在應用程序關閉時也會被調用。但現在什麼都沒有發生 這是做正確的方式嗎? 謝謝