没有未决意图的通知

8 notifications android

我需要创建一个通知,它将显示在顶部但不应导航到任何页面,不应该有任何onclick功能.

这是我用过的代码.

notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.icon,"Notification!", System.currentTimeMillis());

Context context = getApplicationContext();

String notificationTitle = "Message";
String notificationText = Msg;
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myBlog), context, com.gurupro.LiveChat.class);

myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_CLEAR_TOP);




//PendingIntent pendingIntent = PendingIntent.getActivity(Home.this,    0, myIntent, 0);



myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

//myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;



myNotification.setLatestEventInfo(context, notificationTitle,notificationText, pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我.@谢谢

Pan*_*mar 23

使用Intent没有组件,如下所示

PendingIntent contentIntent = PendingIntent.getActivity(
    getApplicationContext(),
    0,
    new Intent(), // add this
    PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)

这提供了一种使用无法打开的方法Activity.