我一直在尝试使用 Glide 库在我的自定义通知中显示 .gif 图像。我只能在通知面板上显示静态图像。
RemoteViews collapsedView = new RemoteViews(getPackageName(), R.layout.notification_collapsed);
RemoteViews expandedView = new RemoteViews(getPackageName(), R.layout.notification_expanded);
collapsedView.setTextViewText(R.id.text_view_collapsed_1,"Hello World!");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(collapsedView)
.setCustomBigContentView(expandedView);
final Notification notification = mBuilder.build();
notificationManager.notify(NOTIFICATION_ID,notification);
notificationTarget = new NotificationTarget(
getApplicationContext(),
R.id.image_view_expanded,
expandedView,
notification,
NOTIFICATION_ID
);
Glide.with(MainActivity.this)
.asBitmap()
.load(R.drawable.giphy)
.into(notificationTarget);
可绘制对象是一个 .gif 文件。当通知弹出时,它会显示静态图像,因为我正在使用 .asBitmap()。我尝试使用
Glide.with(MainActivity.this)
.asGif()
.load(R.drawable.giphy)
.into(notificationTarget);
但我收到错误“无法将方法解析为(NotificationTarget)”。 我四处寻找解决方案,但找不到。 那么如何在android的通知面板中显示带有 Glide 的GIF文件呢?可能吗?
最佳答案
Android 不支持通知中的 GIF 和视频,因为通知是使用 RemoteViews
和 RemoteViews
构建的 doesn't support GIF or Videos .
此外,Glide 维护者也回答了类似的问题 here .我引用的是答案。
It doesn't look like RemoteViews supports setting a Drawable? https://developer.android.com/reference/android/widget/RemoteViews.html.
If there's a way to set an animated drawable in a notification in general, you can probably find a way to do it with a custom Target in Glide.
关于android - 在 android 通知中显示带 Glide 的 GIF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58482692/