使用应用程序的通知调用另一个应用程序/活动



如何使用应用程序的通知启动新应用程序。NotificationManager没有为我提供允许我访问生成的通知的方法。有什么建议吗?谢谢

您必须使用PendingIntent创建通知。来自Android开发者:

Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
private static final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);

其中MyClass是要从通知开始的活动。

相关内容

最新更新