我在下面提供的是一些通知代码。我想通过我的通知代码实现的是,当点击通知时,它将把用户带到特定的类。这是我的通知代码:
final int NOTIF_ID = 1234;
NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.icon, "New Offers CLOSEBY!", System.currentTimeMillis());
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, intentTHING.class), 0);
note.setLatestEventInfo(this, "You have 5 new offers", "Please CLICK THIS Notification to see what is avaliable!", intent);
notifManager.notify(NOTIF_ID, note);
我假设在点击通知时,这里的代码应该带你到声明的类:
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, intentTHING.class), 0);
然而,它没有,通知确实出现,但我看不到我在我的代码中引用的类(即点击时它不会把我带到我想要它的类)。在另一个类中按下按钮后,我当前有通知弹出窗口。一旦用户点击通知,它应该推送该屏幕并将其替换为intentTHING.class。关于我可能缺少的任何想法?
答案 0 :(得分:1)
像这样设置待处理的意图:
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, intentTHING.class), 0);
note .contentIntent = intent;
note.setLatestEventInfo(this, "You have 5 new offers", "Please CLICK THIS Notification to see what is avaliable!", intent);
notifManager.notify(NOTIF_ID, note);
答案 1 :(得分:0)
我不确定,但可以通过这样做来试试..
PendingIntent intent = PendingIntent.getActivity(context,0, 新的Intent(this,intentTHING.class),PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL);