我成功创建了此Android通知,但是我想在触摸时激活我的主要活动。

这是我的代码。

Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // only needed for activity activation

PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, notificationIntent, 0);

Notification notification = new Notification(R.drawable.floating2, "Click to start launcher",System.currentTimeMillis());
notification.setLatestEventInfo(getApplicationContext(), "Start launcher" ,  "Click to start launcher", pendingIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONGOING_EVENT;

NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(ID_NOTIFICATION,notification);

我已经在这里检查了我的工作但仍然无法开始我的活动。

有什么建议么?

===============>>#1 票数:2 已采纳

代替

PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, notificationIntent, 0);

采用

PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);

  ask by Fish translate from so

未解决问题?本站智能推荐: