Skip to content

Commit

Permalink
add large icon entrance
Browse files Browse the repository at this point in the history
  • Loading branch information
hirotakaakita committed Feb 17, 2024
1 parent 7543a1e commit 31a006a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PinpointNotificationPayload internal constructor(
val title: String? = null,
val body: String? = null,
val imageUrl: String? = null,
val largeImageUrl: String? = null,
val action: Map<String, String> = mapOf(),
val silentPush: Boolean = false,
channelId: String? = null,
Expand All @@ -45,6 +46,8 @@ class PinpointNotificationPayload internal constructor(
?: data[PushNotificationsConstants.PINPOINT_NOTIFICATION_BODY]
val imageUrl = data[PushNotificationsConstants.IMAGEURL]
?: data[PushNotificationsConstants.PINPOINT_NOTIFICATION_IMAGEURL]
val largeImageUrl = data[PushNotificationsConstants.LARGEIMAGEURL]
?: data[PushNotificationsConstants.PINPOINT_NOTIFICATION_LARGEIMAGEURL]
val channelId = payload.channelId ?: PushNotificationsConstants.DEFAULT_NOTIFICATION_CHANNEL_ID
val silentPush = data[PushNotificationsConstants.PINPOINT_NOTIFICATION_SILENTPUSH].equals("1")
val action: MutableMap<String, String> = mutableMapOf()
Expand All @@ -62,7 +65,7 @@ class PinpointNotificationPayload internal constructor(
}

return PinpointNotificationPayload(
title, body, imageUrl,
title, body, imageUrl, largeImageUrl,
action, silentPush, channelId,
payload.targetClass, payload.contentProvider
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PushNotificationsConstants {
const val TITLE = "title" // title
const val MESSAGE = "message" // message
const val IMAGEURL = "imageUrl" // imageUrl
const val LARGEIMAGEURL = "largeImageUrl" // largeImageUrl
const val JOURNEY = "journey" // journey
const val JOURNEY_ID = "journey_id" // journey_id
const val JOURNEY_ACTIVITY_ID = "journey_activity_id" // journey_activity_id
Expand All @@ -38,6 +39,7 @@ class PushNotificationsConstants {
const val PINPOINT_NOTIFICATION_TITLE = "$NOTIFICATION_PREFIX$TITLE" // pinpoint.notification.title
const val PINPOINT_NOTIFICATION_BODY = "${NOTIFICATION_PREFIX}body" // pinpoint.notification.body
const val PINPOINT_NOTIFICATION_IMAGEURL = "$NOTIFICATION_PREFIX$IMAGEURL" // pinpoint.notification.imageUrl
const val PINPOINT_NOTIFICATION_LARGEIMAGEURL = "$NOTIFICATION_PREFIX$IMAGEURL" // pinpoint.notification.largeImageUrl
// pinpoint.notification.silentPush
const val PINPOINT_NOTIFICATION_SILENTPUSH = "${NOTIFICATION_PREFIX}silentPush"
const val CAMPAIGN_ID = "campaign_id" // campaign_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.drawable.Icon
import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.IconCompat
import com.amplifyframework.pushnotifications.pinpoint.common.R
import java.net.URL
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -110,7 +112,8 @@ class PushNotificationsUtils(
targetClass: Class<*>?
) {
CoroutineScope(Dispatchers.IO).launch {
val largeImageIcon = payload.imageUrl?.let { downloadImage(it) }
val imageIcon = payload.imageUrl?.let { downloadImage(it) }
val largeImageIcon = payload.largeImageUrl?.let { downloadImage(it) }
val notificationIntent = Intent(context, payload.targetClass ?: targetClass)
notificationIntent.putExtra("amplifyNotificationPayload", payload)
notificationIntent.putExtra("notificationId", notificationId)
Expand All @@ -130,7 +133,7 @@ class PushNotificationsUtils(
builder.apply {
setContentTitle(payload.title)
setContentText(payload.body)
setSmallIcon(R.drawable.ic_launcher_foreground)
setSmallIcon(IconCompat.createWithBitmap(imageIcon))
setContentIntent(pendingIntent)
setPriority(NotificationCompat.PRIORITY_DEFAULT)
setLargeIcon(largeImageIcon)
Expand Down

0 comments on commit 31a006a

Please sign in to comment.