Мое приложение аварийно завершает работу, когда получает уведомление Firebase, дающее E / AndroidRuntime: ФАКТИЧЕСКОЕ ИСКЛЮЧЕНИЕ: Firebase-FirebaseMessagingService Ошибка - PullRequest
0 голосов
/ 17 февраля 2020

У меня есть приложение, которое я загрузил в Google Play Store несколько дней go. но теперь он просто плохо себя ведет, так как не получает никаких уведомлений от firebase. Я проверил журнал функции firebase, но в журнале он показывает, что уведомление отправлено, но не получено на устройстве. Вместо этого приложение вылетает и перестает работать. Во-первых, я подумал, что в коде может быть какая-то ошибка, поэтому я протестировал облачное сообщение непосредственно из firebase, но оно внезапно остановило приложение и приложение упало. В чем может быть ошибка и как это решить ?? Вот мой уровень приложения Gradle.

 implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "com.android.support:support-compat:28.0.0"
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.+'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.squareup.okhttp:okhttp:2.4.0'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-analytics:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebaseui:firebase-ui-database:4.1.0'
implementation 'com.google.firebase:firebase-messaging:17.3.1'
implementation 'com.google.firebase:firebase-ads:17.0.0'
implementation 'com.google.android.gms:play-services-base:16.0.1' //upgraded
implementation 'com.google.android.gms:play-services-auth:16.0.1'

, а вот уровень проекта

classpath 'com.android.tools.build:gradle:3.5.3'
    classpath 'com.google.gms:google-services:4.2.0'

Класс службы сообщений Firebase

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    super.onMessageReceived(remoteMessage);

    String notification_title=remoteMessage.getNotification().getTitle();
    String notification_body=remoteMessage.getNotification().getBody();
    String clickAction=remoteMessage.getNotification().getClickAction();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
        Intent intent=new Intent(clickAction);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        String CHANNEL_ID="MYCHANNEL";
        NotificationChannel notificationChannel=new NotificationChannel(CHANNEL_ID,"name",NotificationManager.IMPORTANCE_LOW);
        PendingIntent pendingIntent=PendingIntent.getActivity(getApplicationContext(),1,intent,PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification=new Notification.Builder(getApplicationContext(),CHANNEL_ID)
                .setContentText(notification_body)
                .setContentTitle(notification_title)
                .setContentIntent(pendingIntent)
                .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
                .setChannelId(CHANNEL_ID)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setAutoCancel(true)
                .build();

        NotificationManager notificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(notificationChannel);
        notificationManager.notify(1,notification);
    }
    else {
        NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(notification_title)
                .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
                .setContentText(notification_body);
        Intent intent=new Intent(clickAction);
        PendingIntent pendingIntent= PendingIntent.getActivity(
                this,
                1,
                intent,
                PendingIntent.FLAG_UPDATE_CURRENT
        );
        builder.setContentIntent(pendingIntent);
        builder.setAutoCancel(true);
        //set id for notification
        int mNotificationid=(int) System.currentTimeMillis();
        //Gets an instance of Notification Manager Service
        NotificationManager notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        //Build notification and issue it
        notificationManager.notify(mNotificationid,builder.build());


    }

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...