【问题标题】:Andorid: how to create a non erasable custom notification in the statusbar?Android:如何在状态栏中创建不可擦除的自定义通知?
【发布时间】:2012-04-29 09:38:08
【问题描述】:

我只想在用户交互期间在状态栏上创建一个自定义通知。

我使用这个代码:

    Notification notification = new Notification(getBatteryStateResource(percent,status), "notify",System.currentTimeMillis());
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = new RemoteViews(mContext.getPackageName(), R.layout.statusbar);
    Intent intent = new Intent(mContext, Activity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
    notification.contentIntent=contentIntent;
    notification.contentView.setOnClickPendingIntent(R.id.imageView, anotherContentIntent);
    NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(42, notification);

此代码仅适用于 android 4 智能手机。在平板电脑上,每次点击通知的imageView,系统都会删除通知。

相反,在 Android 2.3 和 2.2 上,“anotherContentIntent”不启动并且只启动“contentIntent”,为什么??

非常感谢....

【问题讨论】:

    标签: android notifications statusbar


    【解决方案1】:

    FLAG_ONGOING_EVENT 之外使用FLAG_NO_CLEAR

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多