Итак, я использую FCM, чтобы уведомлять пользователя, когда происходят какие-то события. Когда я пытаюсь отправить уведомление с консоли Firebase
, он работает, показывая мне уведомление по умолчанию. Проблема в том, что я использую notification manager
для создания настраиваемых уведомлений, но они не появляются. Я использую следующий код:
public class MyNotificationManager {
public static final int ID_BIG_NOTIFICATION = 234;
public static final int ID_SMALL_NOTIFICATION = 235;
private Context mCtx;
public MyNotificationManager(Context mCtx) {
this.mCtx = mCtx;
}
//the method will show a small notification
//parameters are title for message title, message for message text and an intent that will open
//when you will tap on the notification
public void showSmallNotification(String title, String message, String url) {
Intent intent = new Intent(mCtx, Istoric_Alerte.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
mCtx,
ID_SMALL_NOTIFICATION,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
Notification notification;
notification = mBuilder.setSmallIcon(R.drawable.ic_tick).setTicker(title).setWhen(0)
.setAutoCancel(true)
.setContentIntent(resultPendingIntent)
.setContentTitle(title)
.setLargeIcon(getBitmapFromURL(url))
.setContentText(message)
.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(ID_SMALL_NOTIFICATION, notification);
}
//The method will return Bitmap from an image URL
private 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;
}
}
}
Отладка приложения показала мне, что оно работает нормально, переходя к последней строке notificationManager.notify(ID_SMALL_NOTIFICATION, notification);
со всей необходимой информацией, но когда я go следующий, когда должно появиться уведомление, ничего не происходит. Не знаю, что еще можно проверить, помогите пожалуйста!