1

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

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.");

我的问题如下...

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

4

2 回答 2

4

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

于 2012-05-30T08:41:32.927 回答
2
Intent intent = new Intent(context, class_name.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

并且还使用PendingIntent.getActivity()而不是PendingIntent.getService().

于 2012-05-30T08:48:33.980 回答