Android:无法从通知启动活动
我有以下用于发送通知的代码Android:无法从通知启动活动,android,notifications,Android,Notifications,我有以下用于发送通知的代码 private void publishNotification(Intent intent, String header, String content){ try { NotificationManager manager = getNotificationManager(); Notification notification = new Notification(R.drawable.droid,
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.");
我的问题如下
通知会显示在通知上,甚至在向下滑动后也会显示。问题是,当我单击此通知时,活动不会启动。我想我已经完成了报告中提到的一切。我做错了什么?如果你想启动一个活动,你应该使用
pendingent.getActivity()
而不是pendingent.getService()
如果你想启动一个活动,你应该使用pendingent.getActivity()
而不是pendingent.getService()
也可以使用pendingent.getActivity()
而不是pendingent.getService()
也可以使用pendingent.getActivity()
而不是pendingent.getService()
Intent intent = new Intent(context, class_name.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);