以段落形式通知AlarmManager
问题描述:
尝试让警报管理器使用内部通知时遇到问题。这是为了给应用的用户一个特定点的通知。以段落形式通知AlarmManager
我的闹钟设置在一个片段内,代码如下。
Intent notificationIntent = new Intent(getContext(), DeviceBootReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
int hour = Integer.parseInt(vars.getShowRapport().getFinishTime().split(":")[0]);
int min = Integer.parseInt(vars.getShowRapport().getFinishTime().split(":")[1]);
vars.getShowRapport().getFinishDate().setHours(hour);
vars.getShowRapport().getFinishDate().setMinutes(min);
long futureInMillis = System.currentTimeMillis()+1000*60;
//long futureInMillis = vars.getShowRapport().getFinishDate().getTime();
AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
getFragmentManager().beginTransaction().replace(R.id.makeRapportFragment,fragment).addToBackStack(null).commit();
在我的表现,我有
<receiver android:process=":remote" android:name=".DeviceBootReceiver">/receiver>
最后,在我的接收器,称为DeviceBootReceiver我有。
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ejservicebookincon)
.setContentTitle("Rapport finishing")
.setContentText("Rapport on item should be done.");
Intent notificationIntent = new Intent(context, ServiceRapportMain.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
// Add as notification
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
不知道我的问题是,我的接收器似乎从来没有被激活,所以无法检查的部分工作作为尚未。如果有人能指出我的问题在哪里,请帮助。就像我在Android Studio工作一样。
答
正如我在上面的评论中写道,我有错误是,我使用AlarmManager.ELAPSED_REALTIME_WAKEUP然后在那里我应该在这里你为什么要使用`Android的使用是AlarmManager.RTC_WAKEUP
:过程=“:远程“'? –
使用它作为我遵循的例子使用它,但删除它没有做任何事,但确实发现我的错误。我使用了AlarmManager.ELAPSED_REALTIME_WAKEUP,然后我应该在这里使用AlarmManager.RTC_WAKEUP – silvertaildk