私はfcmを使用してデータを受信しています。イメージを含む通知を作成したいと思います。このデータを取得すると、グライドを使用してロードしようとする画像のURLが取得されますサービスから[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);
}
}
コードが正しく記述され、ログを追加してください。 –
私が得る唯一の出力はnotif.getId()とnotif.getimage()です。私はグライドパートから出力を取得しません。 –
createNotifiationメソッドを呼び出す場所からコードを追加してください。 –