gpt4 book ai didi

安卓 : Unable to launch activity from notification

转载 作者:行者123 更新时间:2023-11-29 14:54:00 25 4
gpt4 key购买 nike

我有以下用于发送通知的代码...

private void publishNotification(Intent intent, String header, String content){
try {
NotificationManager manager = getNotificationManager();
Notification notification = new Notification(R.drawable.droid, header, System.currentTimeMillis());

if(intent != null){
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(this, header, content, pendingIntent);
}

manager.notify(0, notification);

} catch (Exception ex) {
FileManager.writeToLogFile(this.getClass(), "publishNotification", LogMessageType.ERROR, ex.getMessage());
}
}

以及调用它的以下代码...

Intent intent = new Intent();
intent.setAction(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
publishNotification(intent, "Default Password Changed", "Device configuration have changed.\nClick here to change this password.");

我的问题如下...

通知出现在通知上,甚至在它向下滑动之后。问题是当我点击这个通知时, Activity 没有启动。我想我已经完成了 tutorial 中提到的所有事情.我做错了什么?

最佳答案

如果你想启动一个 Activity ,你应该使用 PendingIntent.getActivity() 而不是 PendingIntent.getService()

关于安卓 : Unable to launch activity from notification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10812785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com