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 に答える