GCM not receiving on ColorOS based devices

512 Views Asked by At

I have an android app which sends and receive FCM Messages(Google Firebase Messages).

Its working perfectly as i can receive the messages when my app is not in forground or not using it as i have a service running on it.

Unfortunately its not working when i am not running the app or its in backgroun on some smartphones like OPPO, VIVO or more likely which runs on ColorOS.

What could be the issue? we tried but same happens with WhatsApp as well

Below is my service code:

package com.msb.launcher.services;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;

import com.msb.auth.utils.Keys;
import com.msb.auth.utils.LogUtils;

public class MessagingService extends Service {

    public static final String EXTRA_AUTH_TOKEN = "EXTRA_AUTH_TOKEN";
    public static final String EXTRA_FIREBASE_ID_TOKEN = "EXTRA_FIREBASE_ID_TOKEN";

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            LogUtils.i("Service running.");
            sendEmptyMessageDelayed(100, 500);

        }
    };

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        LogUtils.i("onStartCommand");
        return START_STICKY;
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onTaskRemoved(Intent rootIntent) {
        onDestroy();
        super.onTaskRemoved(rootIntent);
        try {
            handler.removeCallbacksAndMessages(null);
            sendBroadcast(new Intent(Keys.ACTION_RESTART_SERVICE));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void onDestroy() {
        LogUtils.i("Service Destroy");
        handler.removeCallbacksAndMessages(null);
        sendBroadcast(new Intent(Keys.ACTION_RESTART_SERVICE));
        super.onDestroy();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        LogUtils.i("Messaging Service Started");
        handler.sendEmptyMessage(100);
    }
}
0

There are 0 best solutions below