Jake Lee
Jake Lee

Reputation: 7979

Type mismatch. Required: NotificationCompat.Style, Found: Notification.BigPictureStyle

I'm using AndroidX for my app, and am attempting to display a notification with a custom BigPicture style (as in the docs).

However, I cannot use .setStyle(Notification.BigPictureStyle() as the NotificationCompat.Builder is AndroidX, whilst the BigPictureStyle is core android, and seemingly incompatible. Presumably the style has to come from AndroidX, but that doesn't appear to be an import option, even if manually typing in the import.

Troublesome code:

    val notif = NotificationCompat.Builder(context, channelId)
        .setAutoCancel(true)
        .setSmallIcon(R.drawable.ic_notification)
        .setLargeIcon(image)
        .setContentTitle(apod.title)
        .setContentText(apod.desc.take(100))
        .setStyle(Notification.BigPictureStyle()
            .bigPicture(image)
            .bigLargeIcon(null as Bitmap))

Screenshot of error:

enter image description here

Imports:

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color
import android.media.RingtoneManager
import android.os.Build
import androidx.core.app.NotificationCompat

Potentially relevant lines of app-level build.gradle:

implementation 'com.android.support:design:28.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'

And of course in gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

Any idea what changes can be made to allow me to display a BigPicture notification whilst using AndroidX?

Upvotes: 1

Views: 1549

Answers (1)

Jake Lee
Jake Lee

Reputation: 7979

As always, as soon as you write up the question you solve it.

The solution was just to change Notification.BigPictureStyle() to NotificationCompat.BigPictureStyle(), as all AndroidX notification libraries are named NotificationCompat!

Final code:

    val notif = NotificationCompat.Builder(context, channelId)
        .setAutoCancel(true)
        .setSmallIcon(R.drawable.ic_notification)
        .setLargeIcon(image)
        .setContentTitle(apod.title)
        .setContentText(apod.desc.take(100))
        .setStyle(NotificationCompat.BigPictureStyle()
            .bigPicture(image)
            .bigLargeIcon(null))

Upvotes: 4

Related Questions