kotlin – Notifications not showing android API 29-ThrowExceptions

Exception or error:

Ok, guys, idk why but notifications is not showing, on phone with API 29. On Api 21 for example everything is ok. Yes, I tried to read other posts on SO and found there nothing usefull, tried all advices from those posts too.

Min sdk 24, max sdk – 29 in gradle

receiver in manifest:

<receiver android:name=".ui.more_content.receivers.RemindersReceiver">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED"/>
                <action android:name="android.intent.action.PACKAGE_REMOVED"/>
                <data android:scheme="package"/>
            </intent-filter>
        </receiver>

Receiver class:

class RemindersReceiver: BroadcastReceiver() {

    override fun onReceive(p0: Context?, p1: Intent?) {
        // Идентификатор уведомления
        if(p1?.action.equals("android.intent.action.PACKAGE_ADDED")||p1?.action.equals("android.intent.action.PACKAGE_REMOVED")
            ||p1?.action.equals("android.intent.action.PACKAGE_UPDATED")) {
            showNotificationWith("qwqwdqwqs", p0)
        }
    }

    private fun showNotificationWith(message: String, context: Context?) {
        val channelId = "com.example.notif.channelId"
        val channelName = "App status"
        val contentTitle = "Title"
        val notificationManager =
            context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        val activityIntent = Intent()
        val contentIntent: PendingIntent = PendingIntent.getActivity(
            context,
            0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT
        )

        val largeIcon: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.info)
        val notificationBuilder = NotificationCompat.Builder(context, channelId)
            .setSmallIcon(R.drawable.info)
            .setContentTitle(contentTitle)
            .setContentText("asdasdasdasdas")
            .setStyle(
                NotificationCompat.BigTextStyle()
                    .bigText(context.getString(R.string.long_dummy_text))
                    .setBigContentTitle("Big content title")
                    .setSummaryText("Summary is this Text")
            )
            .setLargeIcon(largeIcon)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setColor(Color.RED)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)



        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            val importance = NotificationManager.IMPORTANCE_HIGH
            val notificationChannel = NotificationChannel(channelId, channelName, importance)
            notificationBuilder.setChannelId(channelName)

            notificationManager.createNotificationChannel(notificationChannel)
            notificationManager.notify(
                message.hashCode(), notificationBuilder
                    .setContentIntent(contentIntent).setAutoCancel(true).build()
            )

        } else {
            notificationManager
                .notify(
                message.hashCode(), notificationBuilder
                    .setContentIntent(contentIntent).setAutoCancel(true).build()
            )
        }
    }
}

Appreciate any help, thx in a forward

How to solve:

Those broadcasts have not been delivered to manifest-registered receivers since Android 8.0.

Leave a Reply

Your email address will not be published. Required fields are marked *