Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Custom Push Notifications (Android) #4173

Open
jamilsaadeh97 opened this issue Nov 24, 2023 · 11 comments
Open

Feature Request - Custom Push Notifications (Android) #4173

jamilsaadeh97 opened this issue Nov 24, 2023 · 11 comments
Assignees
Labels
feature-parity A request for a feature that is fully or partially available on another platform (JS, iOS, Android) feature-request A request for a new feature or an enhancement to an existing API or category. push notifications

Comments

@jamilsaadeh97
Copy link
Contributor

jamilsaadeh97 commented Nov 24, 2023

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!

@khatruong2009 khatruong2009 added pending-triage This issue is in the backlog of issues to triage push notifications feature-request A request for a new feature or an enhancement to an existing API or category. feature-parity A request for a feature that is fully or partially available on another platform (JS, iOS, Android) labels Nov 24, 2023
@NikaHsn NikaHsn removed the pending-triage This issue is in the backlog of issues to triage label Dec 1, 2023
@NikaHsn NikaHsn assigned NikaHsn and khatruong2009 and unassigned NikaHsn Dec 1, 2023
@Samaritan1011001
Copy link
Member

Samaritan1011001 commented Dec 5, 2023

Hello @jamilsaadeh97. Thank you for opening this and the detailed description. I want to try and address the second point to see if it helps while rest are considered for future work.

  1. 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.
  1. To set the large icon, you can provide a url on the Pinpoint console when creating a push messaging template. This url will be used to download and set the large icon on the notifications shown. Reference this link for guidance on where the url goes on Pinpoint.
  2. To set the small icon, you can replace or add your icon images to the Android assets in the same name as ic_launcher_foreground so the library can pick it up when creating the notification. This link may be helpful in creating and placing those image assets in the default drawable folder.

Please let me know if either or none work and I will take another look, thank you.

@jamilsaadeh97
Copy link
Contributor Author

jamilsaadeh97 commented Dec 6, 2023

Hi @Samaritan1011001 , thank you for your answer!

My app is using this specific naming ic_launcher_foreground for the app icon and the splash screen, so I changed everything and reserved this name for the notification icon. However the color cannot be changed, and since my app's icon is white, on some devices it might not be very esthetic.

Still I think this needs to be configurable, along with, and maybe most importantly, the text length of the notification. I'm very very limited on the notifications (and the app rely heavily on notifications) since they will be truncated on Android devices.

Thank you!

@Jordan-Nelson
Copy link
Member

Apologies for the delay in response. We are tracking this as a feature request and will post here when we have further updates.

@jamilsaadeh97
Copy link
Contributor Author

jamilsaadeh97 commented Aug 19, 2024

Hello @Jordan-Nelson

I created a PR in the Amplify Android repo fixing the push notification text length and it got merged a while ago.
They released the fix in the 2.20.0 version (currently the latest is 2.21.0). Is it possible to update the version used in the amplify flutter repo ?

Thank you!

@jamilsaadeh97
Copy link
Contributor Author

Hello @Jordan-Nelson , kind reminder on this if it can be included in the next planned release

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Aug 27, 2024
@jamilsaadeh97
Copy link
Contributor Author

Or if its possible for me to manually bump the amplify android version

@Jordan-Nelson
Copy link
Member

@jamilsaadeh97 I think you can pull in a dependency on the Android package and the higher version should be pulled in. I will look to open a PR to bump the version in Amplify Flutter though.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Aug 27, 2024
@jamilsaadeh97
Copy link
Contributor Author

@Jordan-Nelson I opened a PR, please let me know if anything is needed

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Aug 27, 2024
@Jordan-Nelson
Copy link
Member

Thanks for the PR! It will be included in the next release.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Aug 28, 2024
@jamilsaadeh97
Copy link
Contributor Author

Amazing! Thanks a lot @Jordan-Nelson

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Aug 28, 2024
@Jordan-Nelson Jordan-Nelson removed the pending-maintainer-response Pending response from a maintainer of this repository label Aug 28, 2024
@Jordan-Nelson
Copy link
Member

Amplify Flutter v2.4.1 was just released an it includes the android version bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-parity A request for a feature that is fully or partially available on another platform (JS, iOS, Android) feature-request A request for a new feature or an enhancement to an existing API or category. push notifications
Projects
None yet
Development

No branches or pull requests

5 participants