在Android应用程序中创建提醒
问题描述:
我正尝试在我的应用程序中创建每周提醒。为此,我使用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">
我想在此之前进入每周一次的余类该提醒即使在应用程序关闭时也会被调用。但现在什么都没有发生 这是做正确的方式吗? 谢谢
答
我解决了这个问题,并将其发布给将来可能遇到相同问题的人。 在androidmanifest文件中,我错过了'。'即代替“.WeeklyReminder”我是用‘WeeklyReminder’
所以,正确的条目是
<receiver android:name=".WeeklyReminder">