gpt4 book ai didi

在折叠模式下带有图像的 Android 通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:21:13 25 4
gpt4 key购买 nike

我最近看到一条 YouTube 通知,通知的折叠 View 中显示了图片。

现在我知道并且已经使用通知的 BigPictureStyle 在通知展开时在通知中显示图像。但是当使用这种模式时,折叠的通知只显示摘要文本而不是图像的小缩略图。

YouTube 通知在折叠模式下显示图像的缩略图,在展开时显示通常的大图片样式大图像。这也不是大图标,因为当通知展开时,大图标是 YouTube channel 缩略图,图像显示在大图片部分。

我将如何实现这样的目标?这是扩展为大图片 View 的自定义远程 View 吗?

我什至不知道该怎么做。我当前的代码是:

            try{

NotificationCompat.Builder builder = new NotificationCompat.Builder(this,UserRewardChannel);

builder.setAutoCancel(true);

builder.setContentTitle(remoteMessage.getData().get("messagetitle"));

builder.setContentText(remoteMessage.getData().get("messagebody"));

builder.setSmallIcon(R.drawable.ic_foodini_notif);
builder.setColor(ContextCompat.getColor(this,R.color.colorAccent));

builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher2));

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

builder.setSound(defaultSoundUri);

builder.setVibrate(new long[]{0,100,100,100});

if(Boolean.parseBoolean(remoteMessage.getData().get("hasimage"))){

Bitmap image=null;

Response response = null;

try {

OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10000, TimeUnit.MILLISECONDS)
.readTimeout(10000,TimeUnit.MILLISECONDS)
.retryOnConnectionFailure(false)
.build();

Request request = new Request.Builder()
.url(remoteMessage.getData().get("imageurl"))
.build();

response = client.newCall(request).execute();

InputStream imageStream = response.body().byteStream();

image = BitmapFactory.decodeStream(imageStream);

} catch (Exception e) {
//Log.d("FragmentCreate","Some error occured while creating the notification in debug mode",e);
}finally {
try {
response.close();
}catch (Exception e){
//Do nothing
}
}

if(image!=null){
builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image).setSummaryText(remoteMessage.getData().get("messagebody")));

}else{
builder.setStyle(new NotificationCompat.BigTextStyle().setSummaryText(remoteMessage.getData().get("messagebody")).bigText(remoteMessage.getData().get("messagebody")));
}

}else{
builder.setStyle(new NotificationCompat.BigTextStyle().setSummaryText(remoteMessage.getData().get("messagebody")).bigText(remoteMessage.getData().get("messagebody")));
}

int notif_id=(int)(System.currentTimeMillis()%10000);

NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());

notificationManagerCompat.notify(notif_id,builder.build());

} catch (Exception e) {
//Log it
}

preview of the youtube notification

最佳答案

您将需要创建自定义通知布局。有关如何创建这些的指南位于:

https://developer.android.com/training/notify-user/custom-notification

此链接中的代码描述了如何设置通知的小型和扩展布局

关于在折叠模式下带有图像的 Android 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50065916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com