用户关闭应用程序时,Android RemoteView不会消失

时间:2018-07-29 10:23:24

标签: java android kotlin notifications

我正在创建一个RemoteView,向用户提供有关该应用程序的新信息,如下所示:

private fun createRemoteView() {
    mNotificationManager = NotificationManagerCompat.from(activity!!.applicationContext)

    val intent = Intent(activity!!.applicationContext, MainActivity::class.java)
    intent.action = Intent.ACTION_MAIN
    intent.addCategory(Intent.CATEGORY_LAUNCHER)

    val pendingIntent = PendingIntent.getActivity(activity!!.applicationContext, 0,
            intent, 0)

    mRemoteViews = RemoteViews(BuildConfig.APPLICATION_ID, R.layout.notification_layout)
    mRemoteViews.setImageViewResource(R.id.imageView, R.mipmap.time_left_blue)

    mBuilder = NotificationCompat.Builder(activity!!.applicationContext,"1")
    mBuilder.setSmallIcon(R.mipmap.time_left).setAutoCancel(false).setOngoing(true).setContentIntent(pendingIntent).setContent(mRemoteViews)

    mNotificationManager.notify(0, mBuilder.build())
}

我正在每秒更新一次RemoteView布局的TextViews,如下所示:

mRemoteViews.setTextViewText(R.id.txtCurrentWorktime, msToString(totalWorktime))
mRemoteViews.setTextViewText(R.id.txtPlusMinus, plusMinusTime)
mNotificationManager.notify(0, mBuilder.build())

现在我的问题是,用户关闭应用程序后,通知栏中的RemoteView不会消失,并且也无法将其滑动。我该如何解决?

很好,用户无法在应用程序运行时将RemoteView滑走,这就是我想要的。

0 个答案:

没有答案