我正在使用fcm接收数据,我想创建一个包含图像的通知。当我得到这些数据时,我得到图像的网址,我尝试使用滑动加载,但滑动拒绝从服务中触发[ FirebaseMessagingService ]
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private final String TAG = getClass().getName();
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
try {
if (remoteMessage.getData().containsKey("notification")) {
Gson gson = new Gson();
Notif notif = gson.fromJson(remoteMessage.getData().get("notification"), Notif.class);
politicoDataRepository.getPolitico(notif.getPolitico_id())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(politico -> {
createNotifiation(notif, getApplicationContext());
}, throwable -> Log.e("Error", throwable.getMessage() + " " + TAG));
} else {
Log.i("datFirebase", remoteMessage.getFrom() + " " + remoteMessage.getData().get("id"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
realm.close();
}
}
private void createNotifiation(Notif notif, Context context) {
final RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_item);
remoteViews.setImageViewResource(R.id.notif_image, R.mipmap.ic_launcher);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(notif.getTitle())
.setContentText(notif.getMessage())
.setContent(remoteViews)
.setPriority(NotificationCompat.PRIORITY_MIN);
final Notification notification = mBuilder.build();
if (android.os.Build.VERSION.SDK_INT >= 16) {
mBuilder.setCustomBigContentView(remoteViews);
}
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(141, notification);
NotificationTarget notificationTarget = new NotificationTarget(this, remoteViews, R.id.notif_image, notification, 141);
Glide.with(this)
.load(notif.getImage())
.asBitmap()
.into(notificationTarget);
}
}
答案 0 :(得分:1)
尝试 NotificationTarget 。这是链接Glide — Loading Images into Notifications and AppWidgets
或者您可以尝试这样
remoteViews.setImageViewBitmap(R.id.noti_article_1_imageview,getBitmapFromURL (selectedList [0] .getImageUrl()));
remoteViews.setImageViewBitmap(R.id.noti_article_2_imageview,getBitmapFromURL (selectedList 1 getImageUrl()。));
public Bitmap getBitmapFromURL(String strURL) {
try {
URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
答案 1 :(得分:0)
antlr-2.7.7.jar
commons-collections-3.2.1.jar
dom4j-1.6.1.jar
javassist-3.12.1.GA.jar
hibernate-core-4.0.1.Final.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
jboss-logging-3.1.0.CR2.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar