我编写了这段代码,每天都会执行并显示一个通知:
class DailyNotification extends BroadcastReceiver {
// Register the alarm and set it at 7am everyday (repeating mode)
public static void registerAlarm(Context paramContext) {
Calendar calendar = Calendar.getInstance();
if (calendar.get(Calendar.HOUR_OF_DAY) >= 7) {
calendar.add(7, 1);
}
calendar.set(Calendar.HOUR_OF_DAY, 7);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);
// PendingIntent that will perform a broadcast
PendingIntent localPendingIntent = PendingIntent
.getBroadcast(
paramContext,
22341,
new Intent(
"com.bestweightmanager.example.exampledailynotification.DAILY_NOTIFICATION"),
PendingIntent.FLAG_UPDATE_CURRENT);
// Retrieve an AlarmManager to set a repeating daily alarm
((AlarmManager) paramContext.getSystemService("alarm")).setRepeating(1,
calendar.getTimeInMillis(), 1000,
localPendingIntent);
}
}
清单文件如下所示:
<receiver
android:name=".utils.DailyNotification"
android:process=":remote" >
<intent-filter>
<action android:name="com.bestweightmanager.example.exampledailynotification.DAILY_NOTIFICATION" />
<action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
但我没有收到任何通知。谁能建议我如何解决这个问题?
另外,下面的代码是什么意思
Calendar calendar = Calendar.getInstance();
if (calendar.get(Calendar.HOUR_OF_DAY) >= 7) {
calendar.add(7, 1);
}