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.
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.
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)
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.
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>
© 2022 - 2024 — McMap. All rights reserved.