【问题标题】:Issues with notification pending intent通知待处理意图的问题
【发布时间】:2012-08-28 11:44:25
【问题描述】:

我正在尝试启动不可取消的持续通知,但无论我尝试什么,它都是可取消的。

代码:

    NotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.btn_rating_star_on_pressed_holo_light;
    long when = System.currentTimeMillis();

    notification = new Notification(icon, getString(R.string.notificationMSG), when);
    notification.ledARGB = 999;

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, Notification.FLAG_ONGOING_EVENT + Notification.FLAG_NO_CLEAR + Notification.FLAG_SHOW_LIGHTS);

    notification.setLatestEventInfo(context, getString(R.string.app_name), getString(R.string.notificationMSG), contentIntent);

    notificationManager.notify(Global.NOTIFICATION_ID,notification);

我还想知道一旦启动它的活动完成后如何让它消失。尝试执行以下操作,但它只工作了几次。

@Override
protected void onDestroy(){
    notificationManager.cancel(Global.NOTIFICATION_ID);
    super.onDestroy();
}

【问题讨论】:

  • 没用。就好像实际上没有任何标志被激活。 LED 也不工作。

标签: android notifications android-pendingintent


【解决方案1】:
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;

由于某些愚蠢的原因,我们不能将标志直接放在PendingIntent 中,而是需要以这种方式设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-19
    相关资源
    最近更新 更多