Skip to content

Feature Request - Custom Push Notifications (Android) #4173

Open
@jamilsaadeh97

Description

@jamilsaadeh97

This is a feature request to make the push notifications that are received on Android more customized and actually aligned with iOS.
Currently, there's a lot of limitations on the notifications that can be sent to Android:

  1. If text is more than ~100 characters, it gets truncated. On iOS it does not.
    fix(notifications): Prevent notifications text from being truncated amplify-android#2856

  2. The notification icon can't be changed and I'm stuck with a white square instead of my app logo. On iOS it's perfect.

  3. Impossible to send high importance notifications or "heads-up"(official Android term) notifications.

I did some digging into the Android imported packages of Amplify Push Notifications in Android Studio and I found this from package com.amplifyframework.pushnotifications.pinpoint (filename is PushNotificationsUtils.kt):

    fun showNotification(
        notificationId: Int,
        payload: PinpointNotificationPayload,
        targetClass: Class<*>?
    ) {
        CoroutineScope(Dispatchers.IO).launch {
            val largeImageIcon = payload.imageUrl?.let { downloadImage(it) }
            val notificationIntent = Intent(context, payload.targetClass ?: targetClass)
            notificationIntent.putExtra("amplifyNotificationPayload", payload)
            notificationIntent.putExtra("notificationId", notificationId)
            val pendingIntent = PendingIntent.getActivity(
                context,
                notificationId,
                notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
            )
            val notificationChannel = retrieveNotificationChannel()
            val builder = if (isNotificationChannelSupported() && notificationChannel != null) {
                NotificationCompat.Builder(context, payload.channelId ?: notificationChannel.id)
            } else {
                NotificationCompat.Builder(context)
            }

            builder.apply {
                setContentTitle(payload.title)
                setContentText(payload.body)
                setSmallIcon(R.drawable.ic_launcher_foreground)
                setContentIntent(pendingIntent)
                setPriority(NotificationCompat.PRIORITY_DEFAULT)
                setLargeIcon(largeImageIcon)
                setAutoCancel(true)
            }

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

Specifically the builder.apply part, it shows that the smallIcon is predefined so we should follow it. The large texts are not handled like this, therefore, it gets truncated and the priority is set as NotificationCompat.PRIORITY_DEFAULT so we can't have higher importance notifications.

I don't know if I can manually override these properties.

Please let me know if I need to raise this request in another repo. Also I'm happy to contribute into this by raising a PR so please give me some guidance on where should this be done.

Thank you!

Metadata

Metadata

Assignees

Labels

feature-parityA request for a feature that is fully or partially available on another platform (JS, iOS, Android)feature-requestA request for a new feature or an enhancement to an existing API or category.push notifications

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions