FCM通知在Android中,当应用程序在后台或关闭时,通知栏中不显示可展开的图片。

10 浏览
0 Comments

FCM通知在Android中,当应用程序在后台或关闭时,通知栏中不显示可展开的图片。

public void backGroundNotification() {

Intent intent = new Intent(this, MainActivity.class);

// 发送数据给NotificationView类

intent.putExtra("title", title);

intent.putExtra("text", body);

intent.putExtra("imageUrl", imageUrl);

intent.putExtra("type", type);

intent.putExtra("id", id);

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

pendingIntentPromo = PendingIntent.getActivity(this,0,intent, PendingIntent.FLAG_ONE_SHOT);

new LoadBitmap().execute("");

}

private class LoadBitmap extends AsyncTask {

@Override

protected String doInBackground(String... params) {

try {

bit = Glide.

with(MyFirebaseMessagingService.this).

load(imageUrl).

asBitmap().

into(100, 100). // 宽度和高度

get();

} catch (Exception e) {

e.printStackTrace();

Log.e("noti exp", e + "");

}

return null;

}

@Override

protected void onPostExecute(String s1) {

if (bit != null) {

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MyFirebaseMessagingService.this)

.setSmallIcon(R.drawable.app_icon)

.setContentTitle(title)

.setContentText(body)

.setAutoCancel(true)

.setTicker("DealDio")

.setSound(sound)

.setVibrate(vibration)

.setContentIntent(pendingIntentPromo)

.setStyle(new NotificationCompat.BigPictureStyle()

.bigPicture(bit)

.bigLargeIcon(null)

.setSummaryText(body));

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, notificationBuilder.build());

}

}

}

我已经搜索了很多关于此问题的解决方案,但始终只能找到在后台获取通知或数据载荷问题的解决方案。根据我的理解,位图无法在后台创建。

我已经在使用数据载荷,并在后台获得通知,它们显示在通知栏中,但在前台中,展开的图像不显示,而在前台中它正常工作。

0