如何编写一个通知,点击时绝对没有任何意义?

Mel*_*Mel 11 notifications android

我已经看到很多关于如何在用户点击通知时发生某些事情但我实际上不希望发生任何事情的例子.如果用户点击通知,我希望通知只是消失,用户不会被带到任何地方.

在下面的代码中,当FLAG_AUTO_CANCEL清除状态栏中的通知时,当用户点击我的通知时,他们将被带到"MyActivity".

如何创建无效的通知?

Notification notification = new Notification(R.drawable.success, res.getString(R.string.messages_sent), System.currentTimeMillis());

        //Define the expanded message and intent
        Context context = getApplicationContext();
        CharSequence contentTitle = res.getString(R.string.messages_sent_ellipsis);


        Intent notificationIntent = new Intent(this, MyActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0 );
        notification.setLatestEventInfo(context, contentTitle, mStrSuccessMessage, contentIntent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        //Pass the notification to the notification manager
        mNotificationManager.notify(1, notification);
Run Code Online (Sandbox Code Playgroud)

PH7*_*PH7 22

更改

Intent notificationIntent = new Intent(this, MyActivity.class);
Run Code Online (Sandbox Code Playgroud)

Intent notificationIntent = new Intent();
Run Code Online (Sandbox Code Playgroud)

会做的.要点是,如果你什么都不想要,给它一个空白的意图.