0

Buen dia, tengo un problema con las notificaciones de Firebase, y AndroidStudio y es que la notificacion, "cuando la app esta abierta y le doy click", no hace nada, solo me manda a la pantalla principal de login de la app. si la aplicacion esta cerrada o en segundo plano al darle click si realiza la accion que en este caso es abrir una actividad y pasarle extras, pero si la app esta abierta y le doy click a la notificacion, esta no hace nada, quiero hacer que cuando la app este abierta y llegue la NOTIFICACION, haga lo mismo que cuando le doy click y la app esta cerrada

 @Override
public void onMessageReceived(@NonNull RemoteMessage message) {
    super.onMessageReceived(message);
    String mensaje = message.getFrom();
    Log.e("tokenf", "msg"+mensaje);
    notiTitle=message.getData().get("Title");
    mayorOreo(message.getData().get("Title"), message.getData().get("Detalle"));
}

private void mayorOreo(String titulo, String detalle){
    Uri soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE+ "://" + getPackageName() +"/" + R.raw.song);

    String  id= "mensaje";
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder buldier = new NotificationCompat.Builder(this,id);
    NotificationChannel nc = new NotificationChannel(id, "nuevo", NotificationManager.IMPORTANCE_HIGH);
    AudioAttributes audioAttributes = new AudioAttributes.Builder()
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .setUsage(AudioAttributes.USAGE_ALARM)
            .build();
    //personalizamos la notificacion
    nc.setSound(soundUri, audioAttributes);
    nc.setShowBadge(true);
    nm.createNotificationChannel(nc);
    buldier.setAutoCancel(true).setWhen(System.currentTimeMillis()).
            setContentTitle(titulo).setSmallIcon(R.mipmap.ic_launcher).
            setContentText(detalle).
            setSound(soundUri).
            setContentIntent(clickNoty())
            .setContentInfo("Nuevo");
    Random random = new Random();
    int notifyId = random.nextInt(9000);
    assert nm!=null;
    nm.notify(notifyId, buldier.build());


}

public PendingIntent clickNoty(){
    Intent iNoti = new Intent(this,DetalleAlerta.class);
    String part[] = notiTitle.split(": ");
    iNoti.putExtra("notiIncidenteId",part[1]);
    iNoti.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return PendingIntent.getActivity(this,0, iNoti,PendingIntent.FLAG_MUTABLE| PendingIntent.FLAG_UPDATE_CURRENT);
}

}

3
  • 1
    Hay que poner comas en el texto, lo que dices es que cuando la app esta abierta, al abrir la notificación no hace nada?
    – Jorgesys
    el 5 jul. a las 17:59
  • eso entendí, @Jorgesys . Lo que quiere el user, es que, al pulsar la notificación, sí o sí te lleve a la Activity/view a la que espera llegar, no que no haga nada. (algo así como lo que hacen las notificaciones de whatsApp, supongo) el 5 jul. a las 18:02
  • Si es correcto, cuando la app ya esta abierta y llega la notificacion, al darle click me deberia llevar a una actividad de "detalles" (asi lo hace cuando esta cerrada o en segundo plano) pero en este caso si tengo abierta la app y llega la notificacion, al darle click me manda a la pantalla principal del Login
    – Alberto
    el 6 jul. a las 15:11

1 respuesta 1

0

No encontre la solucion, pero me di cuenta de algo: esto solo pasa en Api 33, que es android 13 en todas las demas versiones de Android la notificicion si abre correctamente al lanzarse el intent y solo pasaba con una actividad en especifico de las 5 que tenia mi app, lo que hice fue mandar a una actividad antes al usuario y de ahi valido si el intent trae datos y lo mando a la actividad correspondiente, no es lo optimo pero al ser un cambio rapido de actividad, el usuario nunca distingue si abrio una actividad antes

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.