NullPointerException из Firebase Messaging в отчетах консоли Google Play - PullRequest
0 голосов
/ 22 декабря 2018

У меня есть опубликованное приложение для Android в Google Play с интегрированной системой обмена сообщениями Firebase.вчера я отправил сообщение с данными Firebase, и в консоли Play было зарегистрировано около 200 сбоев (начиная с версии 4.4 до версии 9 для Android).Но я отлаживал приложение в разных версиях Android и на разных устройствах, при отладке не было сбоев.ниже я добавил следы стека из консоли Play, моего класса FirebaseMessagingService, уровня приложения и уровня проекта.Будем благодарны за любую помощь.

Следы стека из консоли Google Play:

java.lang.NullPointerException: 
  at com.calendar.shannirmala.calendar.b.a (Unknown Source:47)
  at com.calendar.shannirmala.calendar.MyFirebaseMessangingService.a (Unknown Source:162)
  at com.google.firebase.messaging.FirebaseMessagingService.b (Unknown Source:402)
  at com.google.firebase.iid.aj.run (Unknown Source:26)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
  at com.google.android.gms.common.util.a.b.run (Unknown Source:7)
  at java.lang.Thread.run (Thread.java:764)

Мой класс службы обмена сообщениями Firebase:

public class MyFirebaseMessangingService extends FirebaseMessagingService {
    private CharSequence name;
    private int importance;
    private String channelid;
    private String title;
    private String text;
    private String notificationgroup;

    private Notification mNotification;
    NotificationCompat.Builder mBuilder;
    private NotificationManager mNotificationManager;
    private NotificationChannel mChannel;
    private PendingIntent mPendingIntent;
    String currentDateTimeString ,dayoftheweek;
    int id;


    DatabaseHelper myDB;

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.d("FCM Receiver", "FCM ONMSG RECEIVED Called");

        myDB = new DatabaseHelper(this);
        //Object obj = remoteMessage.getData().get("topic");

        if (remoteMessage.getData().size() > 0) {

            Object obj1 = remoteMessage.getData().get("title");
            Object obj2 = remoteMessage.getData().get("text");
            Object obj3 = remoteMessage.getData().get("eventgroup");
            //Object obj4 = remoteMessage.getData().get("date");

            //Log.d("checking", "onmessagereceived called");

            if (obj1 != null && obj2 != null && obj3 != null) {

                //read = obj.toString();
                title = obj1.toString();
                text = obj2.toString();
                notificationgroup = obj3.toString();
                //date = obj4.toString();

                SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
                Date d = new Date();
                dayoftheweek = sdf.format(d);
                currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());


                int uniqe_ID = (int) (System.currentTimeMillis() % Integer.MAX_VALUE);

                long dbid = myDB.insertDataNotification(uniqe_ID, 0, title, text, Integer.parseInt(notificationgroup), dayoftheweek + " " + currentDateTimeString);
                id = (int) dbid;

                notification();
            }
        }else {
            Log.d("FCM Receiver", "FCM ONMSG RECEIVED Called but remote message has no data!");
        }

    }


    private void notification() {

        try {
            int badgeCount = myDB.getunreadnotificationcount();
            ShortcutBadger.applyCount(this, badgeCount);
        }catch (Exception ebd){

        }

        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);



        Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        Intent intent = new Intent(this, Notifications.class);
        intent.putExtra("notification_id", id);

        //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        mPendingIntent = PendingIntent.getActivity(this, id, intent, PendingIntent.FLAG_CANCEL_CURRENT);

        if (SDK_INT >= O) {
            channelid = "channelid";
            name = "Holiday Reminder Notifications";
            importance = NotificationManager.IMPORTANCE_HIGH;

            mChannel = new NotificationChannel(channelid, name, importance);
            mChannel.setDescription(title);
            mChannel.enableLights(true);
            mChannel.setLightColor(Color.GREEN);
            mChannel.enableVibration(true);
            mChannel.setVibrationPattern(new long[] {100, 300, 200, 300});
            mNotificationManager.createNotificationChannel(mChannel);


            mNotification = new Notification.Builder(this, channelid)
                    .setShowWhen(true)
                    .setContentTitle(title)
                    .setContentText(text)
                    .setAutoCancel(true)
                    .setPriority(Notification.PRIORITY_HIGH)
                    .setSound(uri)
                    .setColor(getResources().getColor(R.color.icondef))//this
                    .setStyle(new Notification.BigTextStyle().bigText(text))
                    .setDefaults(Notification.DEFAULT_VIBRATE)
                    .setContentIntent(mPendingIntent)
                    .setSmallIcon(R.mipmap.notification_white)//this
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))//this
                    .setDeleteIntent(getDeleteIntent())
                    .build();

            mNotificationManager.notify(id, mNotification);
        } else if (SDK_INT >= LOLLIPOP){

           mNotification = new Notification.Builder(this)
                    .setShowWhen(true)
                    .setContentTitle(title)
                    .setContentText(text)
                    .setAutoCancel(true)
                    .setSound(uri)
                    .setColor(getResources().getColor(R.color.icondef))
                    .setDefaults(Notification.DEFAULT_VIBRATE)
                    .setStyle(new  Notification.BigTextStyle().bigText(text))
                    .setPriority(Notification.PRIORITY_HIGH)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                    .setContentIntent(mPendingIntent)
                    .setSmallIcon(R.mipmap.notification_lolipop)
                    .setLights(Color.WHITE, Color.RED, Color.GREEN)
                   .setDeleteIntent(getDeleteIntent())
                   .build();
            mNotificationManager.notify(id, mNotification);

        }else if (SDK_INT < LOLLIPOP){


            mBuilder = new NotificationCompat.Builder(getApplicationContext())
                    .setShowWhen(true)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(title)
                    .setContentText(text)
                    .setAutoCancel(true)
                    .setSound(uri)
                    .setColor(getResources().getColor(R.color.icondef))
                    .setDefaults(Notification.DEFAULT_VIBRATE)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
                    .setPriority(Notification.PRIORITY_HIGH)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                    .setLights(Color.WHITE, Color.RED, Color.GREEN)
                    .setContentIntent(mPendingIntent)
                    .setDeleteIntent(getDeleteIntent());

            mNotificationManager.notify(id, mBuilder.build());

        }


        //mNotificationManager.notify(notifyId, mNotification);
    }

    protected PendingIntent getDeleteIntent()
    {
        Intent intent = new Intent(this, NotificationBroadcastReceiver.class);
        intent.setAction("notification_cancelled");
        return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    }


}

Уровень приложения: Gradle:

apply plugin: 'com.android.application'

android {
    signingConfigs {
    }
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.calendar.shannirmala.calendar"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 20
        versionName "2.0.5"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation 'com.android.support:support-vector-drawable:27.1.1'
    implementation 'com.android.support:support-media-compat:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.github.prolificinteractive:material-calendarview:2.0.0'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.github.javiersantos:MaterialStyledDialogs:2.1'
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'me.leolin:ShortcutBadger:1.1.19@aar'
    implementation 'com.github.apl-devs:appintro:v4.2.2'
    implementation 'com.google.android.gms:play-services-ads:17.1.2'
}

apply plugin: 'com.google.gms.google-services'

Gradle уровня проекта:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
        maven { url "https://maven.google.com" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...