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>