Why notifications doesn't show as popup?
I implemented notifications in my app with Firebase. I can send notifications form Firebase to my phone but this notifications doesn't show as pop up, I can only see it if I scroll down from the top of my pohone to show notifications. What am I doing wrong?
Here are the notification chanels
// Default notifications channel
String defaultChannelID = getString(R.string.notif_channel_default_ID);
String defaultChannelName = getString(R.string.notif_channel_default_name);
String defaultChannelDescription = getString(R.string.notif_channel_default_desctription);
NotificationChannel defaultChannel = new NotificationChannel(defaultChannelID, defaultChannelName, NotificationManager.IMPORTANCE_HIGH);
defaultChannel.setDescription(defaultChannelDescription);
// Alarms notifications channel
String alarmChannelID = getString(R.string.notif_channel_alarms_ID);
String alarmChannelName = getString(R.string.notif_channel_alarms_name);
String alarmChannelDescription = getString(R.string.notif_channel_alarms_desctription);
NotificationChannel alarmChannel = new NotificationChannel(alarmChannelID, alarmChannelName, NotificationManager.IMPORTANCE_HIGH);
alarmChannel.setDescription(alarmChannelDescription);
// Create channels
NotificationManager notificationManager = getSystemService(NotificationManager.class);
List<NotificationChannel> notificationChannels = Arrays.asList(defaultChannel, alarmChannel);
notificationManager.createNotificationChannels(notificationChannels);
And here the FCM service
import android.app.NotificationManager;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
public MyFirebaseMessagingService() {
}
@Override
public void onNewToken(@NonNull String s) {
Log.e("Token", s);
}
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
Log.e("Notificacion recibida: ", remoteMessage.getData().toString());
if (remoteMessage.getData().size() > 0) {
displayNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
}
}
private void displayNotification(String title, String body){
String CHANNEL_ID = getString(R.string.notif_channel_alarms_ID);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_home)
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationManager.IMPORTANCE_HIGH);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(1, builder.build());
}
}
In other Stackoverflow posts they said that the problem is that I didn't put the notification inportance to HIGH, but, as you can see I writed that and the notifications isn't showing as pop up.
Thanks for ur help
from Recent Questions - Stack Overflow https://ift.tt/3tWGl6l
https://ift.tt/eA8V8J
Comments
Post a Comment