为什么活动是开放点击通知之后

为什么活动是开放点击通知之后

本文介绍了Android的 - 为什么活动是开放点击通知之后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数来显示一个通知,这是我从各种活动呼吁。

I have a function to display a notification, which I call from various activities.

public static void CrearNotificacion(Context pContexto, String pTituloBarra, String pTitulo, String pTexto){
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) pContexto.getSystemService(ns);

    Notification notification = new Notification(R.drawable.icono, pTituloBarra, System.currentTimeMillis());
    notification.defaults |= Notification.DEFAULT_SOUND;

    Intent notificationIntent = new Intent(pContexto, pContexto.getClass());
    PendingIntent contentIntent = PendingIntent.getActivity(pContexto, 0, notificationIntent, 0);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notification.setLatestEventInfo(pContexto, pTitulo, pTexto, contentIntent);
    mNotificationManager.notify(1, notification);
}

运行完美,问题是在通知pressing打开创建通知的活动,这是错误的,我认为当我选择通知notiifcacion活动不应打开。

works perfect, the problem is that pressing on the notification opens the activity that created the notification and that's wrong, I think the notiifcacion activity should not open when I select the notification.

为什么呢?有什么办法可以解决这个问题?

Why? there any way to fix this?

我不希望当我选择通知,打开任何活动。

I do not want to open any activity when I select the notification.

从现在的感谢。

推荐答案

为了有点击通知时,您可以设置一个空的意图不采取行动如下:

In order to have no action taken when clicking the notification, you may set an empty Intent as follows:

Intent notificationIntent = new Intent() ;
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;

这篇关于Android的 - 为什么活动是开放点击通知之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:35