Подтвердить что ты не робот

Android Lock Screen Notification Custom View с пульсацией и двойным нажатием

Я работаю над Android-приложением. В последнем случае используется уведомление с настраиваемым представлением, которое отображается на экране блокировки. К сожалению, я не могу получить эффект пульсации и повышения, когда я использую его, как и другие уведомления. Кроме того, одно касание запускает намерение, которое я настроил, тогда как другие уведомления требуют двойного нажатия.

Я привел минимальный пример проекта в Github:

https://github.com/lpellegr/android-notification-custom-example

В примере приложения есть две кнопки для публикации уведомлений: одна, которая использует настраиваемое представление и имеет проблемы, упомянутые выше, и другое уведомление, использующее системный вид по умолчанию с ожидаемым поведением.

введите описание изображения здесь

Любая идея о том, как получить эффект пульсации и высоты, а также поведение двойного крана (путем сохранения пользовательского представления) приветствуется.

PS: Я нацелен на API 19+, и я хочу использовать настраиваемый макет представления для уведомления вместе с setOnClickPendingIntent, поскольку только этот прослушиватель позволяет открывать действие независимо от режима безопасности устройства.

4b9b3361

Ответ 1

Удалите setOnClickPendingIntent из метода publishNotificationWithCustomView и добавьте setContentIntent в конструктор уведомлений:

private void publishNotificationWithCustomView() {
    String title = "Notification Custom View";
    String content = "No ripple effect, no elevation, single tap trigger";
    Context context = getApplicationContext();

    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context)
                    .setWhen(System.currentTimeMillis())
                    .setDefaults(DEFAULT_ALL)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setOnlyAlertOnce(true)
                    .setAutoCancel(false)
                    .setColor(ContextCompat.getColor(context, R.color.colorAccent))
                    .setContentTitle(title)
                    .setContentText(content)
                    .setOngoing(true)
                    .setCategory(NotificationCompat.CATEGORY_ALARM)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setContentIntent(createLockscreenNotificationPendingIntent(context));

    int notificationLayoutResId = R.layout.lock_screen_notification;

    // using folder layout-vX is having issue with LG devices
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        notificationLayoutResId = R.layout.lock_screen_notification_android_n;
    }

    RemoteViews remoteView = new RemoteViews(
            context.getPackageName(), notificationLayoutResId);
    remoteView.setTextViewText(R.id.title, title);
    remoteView.setTextViewText(R.id.text, content);

    builder.setCustomContentView(remoteView);

    Notification notification = builder.build();
    publishNotification(context, notification, 7);
}

Затем удалите android:clickable="true" из lock_screen_notification.xml и lock_screen_notification_android_n.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="64dp">

    ....