is it possible to add video in android push notification?
Asked Answered
R

3

7

Is ti possible too embedded video into android rich notification as it possible in iOS? I know that the android officially still do not support that, but it may be some tricky way to improvise that? :)

Thanks in advance.

Rosalindrosalinda answered 22/8, 2018 at 10:12 Comment(7)
Most android developers have no idea how it is done in iOS. Where do you want to show that video?Fragmentary
just create a custom Notification layout and add an exo player there & listen for "notification receive" with a broadcast.receiver, which gets the video ID/URL pushed. "thanks in advance" does not motivate me to program that for you.Interplanetary
You have to send url as notification payload and build proper notification ui in application.Spermatocyte
@Spermatocyte can you provide me some example?Rosalindrosalinda
@DragisaDragisic hey is it done? I need to do the same.Vermeil
@SapnaSharma I didn't menage to make video in push notifications. :(Rosalindrosalinda
Not sure but it may be possible. I am searching further about it.Nappie
I
3

There is no way to show video on RemoteViews. You can use only widgets that are described in the official documentation

As you show in comments as example, it's not a video in the notification, it's a simple image (but as I assume, when you click on it, some apps, that can show video by URL (or something like that), will be started and showing you content, that's all)

Intransitive answered 28/9, 2018 at 17:0 Comment(1)
Not sure but it may be possible. I am searching further about it.Nappie
S
1

You have to implement FCM Messages 'Data message'. This will allow you to send custom json data. More info here: FCM documentation. Such message will not be shown automatically - after receiving you need to build your custom notification layout. More info here: Android dev documentation It's not possible to show video directly on notification panel. Checkout how youtube does it.

Spermatocyte answered 22/8, 2018 at 12:16 Comment(1)
Not sure but it may be possible. I am searching further about it.Nappie
R
0

Create a notification payload with the video link: When sending a notification from your server or Firebase console, include a data payload with the video link:

{
  "to": "<FCM_TOKEN>",
  "data": {
    "title": "Your notification title",
    "body": "Your notification message",
    "videoUrl": "https://example.com/your_video.mp4"
  }
}

Handle the notification in your Android app:

if (remoteMessage.getData().containsKey("videoUrl")) {
    String videoUrl = remoteMessage.getData().get("videoUrl");

    Intent intent = new Intent(this, VideoPlayerActivity.class);
    intent.putExtra("videoUrl", videoUrl);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle("New Video Notification")
            .setContentText("Tap to watch the video")
            .setContentIntent(pendingIntent)
            .setAutoCancel(true);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notificationId, builder.build());
}

Register the service in your AndroidManifest.xml:

<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
Reflective answered 15/5 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.