marlonpya marlonpya - 2 months ago 11
Android Question

not working notificactioncompat with firebase

I don't know but my notification not show.. only see message with Log Consola Android Studio u.u

public class MyFcmListenerService extends com.google.firebase.messaging.FirebaseMessagingService {
public static final String TAG = MyFcmListenerService.class.getSimpleName();

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG,"HECHO");
Log.d(TAG,remoteMessage.getData().get("message"));
Log.d(TAG, "token_test_"+Test.getTest(1).getToken_test());
if (Test.getTest(1).isEstado_token()) {
Log.d(TAG,"bolean1"+String.valueOf(Test.getTest(1).isEstado_token()));
mostrarMensaje(remoteMessage.getData().get("message"));
}
}

private void mostrarMensaje(String mensaje) {
SharedPreferences preferences = getSharedPreferences(Constantes.PREFERENCIA_PARA_PREGUNTAS, Context.MODE_PRIVATE);
int pre_token_count = preferences.getInt(Constantes.KEY_IDENTIFICADOR, 0);

Intent i = new Intent(this, PrincipalActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_ONE_SHOT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("TEST")
.setContentText(mensaje)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVibrate(new long[]{2000, 2000, 2000, 2000, 2000});

NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

manager.notify(pre_token_count, builder.build());

SharedPreferences.Editor editor = preferences.edit();
pre_token_count++;
editor.putInt(Constantes.KEY_IDENTIFICADOR, pre_token_count);
editor.commit();

}


}

My message is this "Bien joven :D"..
enter image description here

fawfaw

Answer

The documentation indicates a Notification is required to have an icon:

A Notification object must contain the following:

  • A small icon, set by setSmallIcon()
  • A title, set by setContentTitle()
  • Detail text, set by setContentText()

Add an icon to your notification with setSmallIcon().

Comments