没有挂起意图的通知

15

我需要创建一个通知,它将显示在顶部,但不应导航到任何页面,也不应具有任何点击功能。

这是我使用的代码。

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

有人能帮助我吗?@谢谢

1个回答

32

在没有组件的情况下使用Intent,如下所示

PendingIntent contentIntent = PendingIntent.getActivity(
    getApplicationContext(),
    0,
    new Intent(), // add this
    PendingIntent.FLAG_UPDATE_CURRENT);

这提供了一种方法,可以防止用户打开一个Activity


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接