Уведомление Marquee теряет фокус и останавливается, когда приходит другое уведомление - PullRequest
0 голосов
/ 09 ноября 2019

У меня есть текущее уведомление с горизонтальным выделением, определяемым:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="52dp"
        android:layout_height="52dp"
        android:background="@mipmap/ic_launcher_round"
        android:contentDescription="@string/app_name" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:duplicateParentState="true"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="false"
            android:singleLine="true" >
            <requestFocus />
        </TextView>

    </LinearLayout>

</LinearLayout>

и

fun createNotificationChannel(context: Context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val name = "channel_name"
        val descriptionText = "channel_description"
        val importance = NotificationManager.IMPORTANCE_HIGH
        val channel = NotificationChannel("CHANNEL_ID", name, importance).apply {
            description = descriptionText
        }

        // Register the channel with the system
        val notificationManager: NotificationManager =
            context.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        notificationManager.createNotificationChannel(channel)
    }
}
suspend fun showNotification(context: Context) {
    var collapsedView = RemoteViews(context.packageName, R.layout.default_notification_collapsed)
    collapsedView.setTextViewText(
                R.id.text,
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")

    val builder = NotificationCompat.Builder(context.applicationContext, "CHANNEL_ID")
        .setSmallIcon(R.drawable.ic_launcher_foreground)
        .setCustomContentView(collapsedView)
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setOnlyAlertOnce(true)
        .setOngoing(true)

    with(NotificationManagerCompat.from(context.applicationContext)) {
        notify(1, builder.build())
    }
}

Это работает на Oreo очень хорошо, но когда приходит уведомление отдругое приложение, шатер останавливается на экране блокировки. Похоже, это происходит с уведомлениями из Gmail и Twitter, но не с системными уведомлениями, такими как «обнаружен открытый Wi-Fi».

Кроме того, похоже, что это происходит не сразу. Когда приходит новое уведомление, оно появляется над моим текущим уведомлением (выделение продолжается), и через несколько секунд андроид переупорядочивает уведомления, поэтому мое текущее уведомление появляется сверху, и выделение останавливается.

Ожидается ли этоповедение? Как я могу предотвратить это?

...