I'm just starting with Firebase
and I was trying with a kind of complex code that I saw on a tutorial, and I get an error, so I just copied a simple code, very basic, but I'm still getting the same error, please help me, I'm gonna put the FirebaseInstanceIdService
and the FirebaseMessagingService
, but if you need further information please let me know.
The error that I'm getting
FATAL EXCEPTION: main
Process: com.bim.tech.construbimapp, PID: 30988
android.app.RemoteServiceException: Bad notification posted from package com.bim.tech.construbimapp: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.bim.tech.construbimapp user=UserHandle{0} id=0 tag=FCM-Notification:250274573 score=0 key=0|com.bim.tech.construbimapp|0|FCM-Notification:250274573|10184: Notification(pri=0 contentView=com.bim.tech.construbimapp/0x1090077 vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE))
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1638)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
FirebaseMessagingService
public class MiFirebaseMessagingService extends FirebaseMessagingService {
public static final String TAG = "SERVICIOS";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String from = remoteMessage.getFrom();
Log.d(TAG, "Mensaje recibido de " + from);
if(remoteMessage.getNotification() != null){
Log.d(TAG, "Notificacion" + remoteMessage.getNotification().getBody());
mostrarNotificacion(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
}
if(remoteMessage.getData().size() > 0 ){
Log.d(TAG, "Data: " + remoteMessage.getData());
}
}
private void mostrarNotificacion(String title, String body) {
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Intent intent = new Intent(this, Activity_Metodos_de_Pago.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.builder)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setSound(soundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
FirebaseInstanceIdService
public class MiFirebaseInstanceIdService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
super.onTokenRefresh();
String token = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Token: " + token);
enviarTokenAlServidor(token);
}
private void enviarTokenAlServidor(String token) {
}
}
Thanks.