1
你好,我有以下功能,顯示在我的應用程序的通知,但我突然開始有一個問題,當我點擊一個通知它不會帶我到我指定的活動.setContentIntent(),這是我的代碼:待定意圖不工作,通知不會打開活動
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void getNotifications() {
ArrayList<com.xxxxxx.app234929.models.Notification> notifications = mNotificationsTable.get();
int requestId = (int) System.currentTimeMillis();
Intent notificationsIntent = new Intent(getApplicationContext(), NotificationsActivity.class);
notificationsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), requestId,
notificationsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.ic_stat_mtgh_notification)
.setColor(getResources().getColor(R.color.colorPrimary))
.setContentTitle("xxxxxx")
.setContentText("You have "+(notifications.size() > 1 ? "new updates" :"a new update"))
.setNumber(notifications.size())
.setContentIntent(intent)
.setDefaults(Notification.DEFAULT_VIBRATE |
Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS))
.setBigContentTitle("xxxxxx");
for (int i=0; i < notifications.size(); i++) {
inbox.addLine(notifications.get(i).getMessage());
};
Notification notification = inbox.build();
NotificationManager notificationManager = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notification);
}
我GOOGLE了很多的解決方案,並試圖他們,但他們沒有工作對我來說,現在我不知道我在做什麼錯在這裏。
我改變了他的活動的名稱和它的工作,改變了它回來了,它沒有工作,所以我會說這只是其中的一件事,稍後會通過我的代碼看看真正的問題是什麼。 – user3718908