Problem in Firebase Notification. Does not display when going through notification

Asked

Viewed 82 times

0

I’m having a problem with the notification. I tried both Notification and Notificationcompat simply does not display it. Receives the firebase response well, but when showing the notification does not appear. I used the grandle version of SDK 22 after I passed to 27 presented this problem. No error appears in any part of the code. Can someone help me on this?

Below my code where it was implemented.

/**
 * Created by iNux on 23/10/2017.
 */

public class CustomFirebaseMessagingService extends FirebaseMessagingService {

/**
 * 0 - Tarefas.<p>
 * 1 - Autorização.</p>
 * 2 - Vistoria.<p>
 * 3 - Avaliação.</p>
 * 99 - Notificacao Geral.
 */

private String modulo;
private String codigoRegistro;
private Bitmap imagem;

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    modulo = (remoteMessage.getData().get("modulo"));
    codigoRegistro = (remoteMessage.getData().get("codigoRegistro"));
    ParametroSingleton.ID_TABELA = Integer.parseInt(codigoRegistro);

    showNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
    //Log.d(TAG, "From: " + remoteMessage.getFrom());
    //Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getTitle());
    //Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}

private void showNotification(String titulo, String mensagem) {
    Intent i = null;

    ParametroSingleton.CONTROLE_NOTIFICACAO = true;

    imagem = null;
    if(ParametroSingleton.ID_TABELA > 0){
        switch (Integer.parseInt(modulo)){
            case 0: //Tarefas.
                imagem = BitmapFactory.decodeResource(getResources(),
                        R.mipmap.ic_servico);
                i = new Intent(this, Tela_OrdemServico_Editar.class);
                i.putExtra("ID", Integer.parseInt(codigoRegistro));
                break;
            case 1: //Autorização.
                imagem = BitmapFactory.decodeResource(getResources(),
                        R.mipmap.ic_autorizacao);
                i = new Intent(this, Tela_Autorizacao_Editar.class);
                i.putExtra("ID", Integer.parseInt(codigoRegistro));
                break;
            case 2: //Vistoria.
                imagem = BitmapFactory.decodeResource(getResources(),
                        R.mipmap.ic_vistoria);
                i = new Intent(this, Tela_Vistoria_Editar.class);
                i.putExtra("ID", Integer.parseInt(codigoRegistro));
                break;
            case 3: //Avaliação.
                imagem = BitmapFactory.decodeResource(getResources(),
                        R.mipmap.ic_avaliacao);
                i = new Intent(this, Tela_Avaliacao.class);
                i.putExtra("ID", Integer.parseInt(codigoRegistro));
                break;
            case 99:

                break;
            default:
                i = new Intent(this, Tela_OrdemServico_Editar.class);
                i.putExtra("ID", Integer.parseInt(codigoRegistro));
                break;
        }
    }else{
        if(Integer.parseInt(modulo) != 99){
            i = new Intent(this, Tela_OrdemServico_Editar.class);
        }
    }

    if(Integer.parseInt(modulo) != 99){
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
        Notification.Builder builder = null;
        builder = new Notification.Builder(this)
                .setAutoCancel(true)
                .setContentTitle(titulo)
                .setContentText(mensagem)
                .setStyle(new Notification.BigTextStyle()
                        .bigText(mensagem))
                .setSmallIcon(R.mipmap.ic_concluida)
                .setLargeIcon(imagem)
                //.setNumber(2)
                .setDefaults(Notification.DEFAULT_ALL)
                //.addAction(R.mipmap.ic_concluida, "Visualizar", pendingIntent)
                .setContentIntent(pendingIntent);

        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        manager.notify(0, builder.build());
    }else{
        Notification.Builder builder = null;
        builder = new Notification.Builder(this)
                .setAutoCancel(true)
                .setContentTitle(titulo)
                .setContentText(mensagem)
                .setStyle(new Notification.BigTextStyle()
                        .bigText(mensagem))
                //.setNumber(3)
                .setSmallIcon(R.mipmap.ic_concluida)
                .setDefaults(Notification.DEFAULT_ALL);

        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        manager.notify(0, builder.build());
    }
    if(imagem != null){
        imagem.recycle();
    }
}

}

1 answer

0

After android 8 or higher, it is mandatory to set the CHANNEL and IMPORTANCE.

Behold HERE the documentation that speaks covers it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.