0
我试图安排一段时间后通知出现,但不是显示通知,而是打开应用程序。计划的定期通知,但其开放的应用程序
下面的代码:
//Build Notification
notif.setSmallIcon(R.drawable.ico);
notif.setTicker("New Notification!");
notif.setWhen(System.currentTimeMillis());
notif.setContentTitle("Notification Title");
notif.setContentText("Thiis is notification message");
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);;
Calendar calendar = Calendar.getInstance();
// calendar.set(Calendar.HOUR_OF_DAY, 12);
// calendar.set(Calendar.MINUTE, 00);
// calendar.set(Calendar.SECOND, 00);
//Intent when clicked
Intent i = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
notif.setContentIntent(pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 40* 1000, pendingIntent);
//Builds notification and issues
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(uniqueId,notif.build());
我还添加在清单两行:
<uses-permission android:name="info.geekstart.www.notificationapp.SET_ALARM"/>
<reciever android:name=".AlarmReciever"></reciever>