0

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);
    }
}
Amrish Kakadiya
  • 974
  • 1
  • 7
  • 25
Prakash
  • 357
  • 2
  • 14
  • Can it be that who is using ColorOS is located in China and can't access GCM or firebase? – Magnetic_dud Nov 04 '17 at 16:23
  • Or maybe it's like MIUI, it has a super aggressive task killer (the one that actually kill background apps, not just politely ask them) unless you disable "optimized battery" for your app. On my MIUI device I can't get push notifications if I don't place the app in the whitelist. If this is true, you have to detect ColorOS and tell the user to place your app in the whitelist. – Magnetic_dud Nov 04 '17 at 16:26
  • @Prakash You may want to check https://www.forbes.com/sites/bensin/2017/07/28/how-to-fix-push-notifications-on-oppo-phones/#6980e1b51735 – Raxit Sheth Feb 27 '20 at 22:31

0 Answers0