Skip to content

Rich notifications

Alexander Boldyrev edited this page Jan 15, 2024 · 18 revisions

Mobile messaging platform enables you to attach an image URL to notification since MM SDK version 1.6.4, Huawei SDK 1.0.0.

Requirements

  • Android MM SDK 1.6.4 and above or Huawei SDK 1.0.0 and above
  • for expanded, big picture view use Android version 4.1+ (Jelly Bean, API Level 16). image in normal notification view is supported on all Android versions
  • supported: image, gif
    • file formats: JPEG, PNG, GIF (only static image is shown if gif is provided)
  • valid URL provided
  • by Google, recommended aspect ratio for images is approximately 2:1. Android scales, centres and sometimes crops the image, so try to position image content in the centre, and use landscape. You might also check image preview if you’re using push broadcast campaigns on our "Analyze" page
  • max resolution defined by Google is up to 2048x1024, but we recommend not to go over 1280x1280/300Kb
  • message text is shown as a one-liner with big image preview - make it short and put focus on the image

Notice:

From version 12.x onwards, HTTP is disabled by default for security reasons, see migration guide for more information.

Send rich notification

In order to receive images through Push within Notification Centre, you need to create a New Push Campaign on Portal or send a message through Push API with contentUrl parameter.

Creating campaign on Portal:

Rich notification - CUP - step 1 Rich notification - CUP - step 2 Rich notification - CUP - step 3

Receive it on device

Provided image will be displayed in the notification drawer where default rich notification’s design correlates with OS version. As of API 16 - Jelly Bean, image downloaded from provided URL will be displayed not only in normal view, but also in expanded, big view.

Rich notification - Android 7.1 Rich notification - Android 4.4
Preview of rich notifications on Android 7.1 and Android 4.4

The following example shows how you can retrieve the content URL from within your application by subscribing to a message received Event:

// declare message receiver
private val messageReceiver = object: BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val message = Message.createFrom(intent.extras)
        val myImage = message.contentUrl
        // your additional code
    }
}

override fun onResume() {
    super.onResume()
    // subscribe to MESSAGE_RECEIVED event
    val localBroadcastManager = LocalBroadcastManager.getInstance(this)
    localBroadcastManager.registerReceiver(messageReceiver, IntentFilter(Event.MESSAGE_RECEIVED.key))
}
expand to see Java code

// declare message receiver
private final BroadcastReceiver messageReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        Message message = Message.createFrom(intent.getExtras());
        final String myImage = message.getContentUrl();
	
	// your additional code
    }
}

@Override
protected void onResume() {
    super.onResume();
    // subscribe to MESSAGE_RECEIVED event
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
    localBroadcastManager.registerReceiver(messageReceiver, new IntentFilter(Event.MESSAGE_RECEIVED.getKey()));
}
Clone this wiki locally