我一直在尝试让通知在正确的时间在 Android 上启动。我希望他们在 App 启动后 2 分钟内起飞。如果我可以让它在这里工作,我可以很容易地让它在我真正需要的地方工作。日志显示所需的代码行正在运行,但通知从未启动。我花了超过 8 个小时来尝试调试它,却一无所获。任何帮助都会很棒。
这是我创建的提醒代码:
final PendingIntent pi = PendingIntent.getBroadcast(this.mContext,
0,
i,
PendingIntent.FLAG_ONE_SHOT);
TimeZone timeZone= TimeZone.getDefault();
Calendar time= Calendar.getInstance(timeZone);
time.add(Calendar.MINUTE, 2);
this.mAlarmManager.set(AlarmManager.RTC_WAKEUP,
time.getTimeInMillis(),
pi);
Log.d ("setReminder",time.getTime().toLocaleString());
现在下面是我的OnAlarmRecieve
代码,根据日志,它永远不会在 2 分钟后运行。类扩展BroadcastReceiver
@Override
public void onReceive(final Context context,
final Intent intent) {
Log.d(TAG, "Recieved wake up cal from Alarm Manger");
final String tableName = intent.getStringExtra(IntentExtraStringStorage.TABLE_NAME);
final long rowID = intent.getLongExtra(IntentExtraStringStorage.ROW_ID,
-1);
final String titleString = intent.getStringExtra(IntentExtraStringStorage.NOTIFICATION_TITLE);
final String notificationString=intent.getStringExtra(IntentExtraStringStorage.NOTIFICATION_NOTE);
WakeUpReminderIntentService.acuireStaticLock(context);
/*if (tableName== Task.TABLE_NAME) {
launchTaskView(context, rowID);
}
else {
Log.e (TAG, "Did not Launch");
Toast.makeText(context, "Did not work right", Toast.LENGTH_SHORT).show();
}*/
Intent i = new Intent (context, ReminderService.class);
i.putExtra("taskID", rowID);
i.putExtras(intent.getExtras());
Log.d(TAG, "Launched task");
//TODO Added code to build the screen correctly
//FIXIT this need to be finished.
context.startService(i);
}]=