Android app crashes when fcm is sent and app is open

Viewed 2026

I'm using firebase with my android app to send push notifications. When I send a message and the app is closed, the notification is received, the intent works and everything is fine. But when the app is open and I send a message, it crashes with this error from the getColor() method:

Exception java.lang.NoSuchMethodError: No virtual method getColor(I)I in class Lcom/kinectafrica/android/service/FirebaseMessagingService; or its super classes (declaration of 'com.kinectafrica.android.service.FirebaseMessagingService' appears in /data/app/com.kinectafrica.android-1/base.apk)
com.kinectafrica.android.service.FirebaseMessagingService.sendNotification (FirebaseMessagingService.java:45)
com.kinectafrica.android.service.FirebaseMessagingService.onMessageReceived (FirebaseMessagingService.java:33)
com.google.firebase.messaging.FirebaseMessagingService.zzo ()
com.google.firebase.messaging.FirebaseMessagingService.zzn ()
com.google.firebase.messaging.FirebaseMessagingService.zzm ()
com.google.firebase.iid.zzb$2.run ()
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:587)
java.lang.Thread.run (Thread.java:818)

This is my FirebaseMessagingService class:

package com.kinectafrica.android.service;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.firebase.messaging.RemoteMessage;
import com.kinectafrica.android.R;
import com.kinectafrica.android.activity.SplashScreenActivity;

/**
 * Made by acefalobi on 5/16/2017.
 */

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {

    int notifyId = 0;
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d("Service", "From: " + remoteMessage.getFrom());

        if (remoteMessage.getData().size() > 0) {
            Log.d("Service", "Message data payload: " + remoteMessage.getData());
        }

        if (remoteMessage.getNotification() != null) {
            Log.d("Service", "Message notification: " + remoteMessage.getNotification().getBody());
        }
        sendNotification(remoteMessage.getData().get("message"));
    }

    private void sendNotification(String message) {
        Intent intent = new Intent(this, SplashScreenActivity.class);
        intent.putExtra("isNotify", true);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_notify)
                .setColor(getColor(R.color.colorAccent))
                .setContentTitle("Kinect")
                .setWhen(System.currentTimeMillis())
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(uri)
                .setContentIntent(pendingIntent)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(notifyId, builder.build());
        notifyId++;
    }
}

Any idea what could be causing this? Thanks.

2 Answers
Related