Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oppo, vivo app kill notification not coming in android fcm

Testing app in motorola , samsung working fine when app is killed. but when i test app in vivo, oppo not working in case of app is destroyed.

 public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e(TAG, "From: " + remoteMessage.getFrom());

    if (remoteMessage == null)
        return;

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
        //  handleNotification(remoteMessage.getNotification().getBody());
    }

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());

        try {
            JSONObject json = new JSONObject(remoteMessage.getData().toString());
            handleDataMessage(json);
        } catch (Exception e) {
            Log.e(TAG, "Exception: " + e.getMessage());
        }
    }
}

Android Manifest xml:

 <service
        android:name="notification.MyFirebaseMessagingService"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service android:name="notification.MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

I am not getting message in case of vivo, oppo any help would be recommended.

like image 249
Harish Avatar asked Nov 03 '18 05:11

Harish


People also ask

Can FCM notification on Android overwrite previous one?

If not specified, each request creates a new notification. If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.

How do I test FCM push notifications Android?

Send a test notification messageOpen the Notifications composer and select New notification. Enter the message text. Select Send test message. In the field labeled Add an FCM registration token, enter the registration token you obtained in a previous section of this guide.


2 Answers

Infinix Note 5 (Android One- Oreo) and Oppo F9(Oreo) are not getting push notification if app is killed, they work fine if app is in background or foreground.

Chinese ROMs using (Oxygen OS, MIUI etc) when the apps are swiped from the recent app tray your app gets terminated ( similar to Force Stop). And due to this every task running in the background like Services, Jobs gets killed with the app. Even High priority FCM doesn’t see the daylight in Chinese ROMs

Real time problems :

1) You can’t fetch location of the user. So, no app would work properly if it depends on real-time location

2) You can’t recevie the FCM high priority notifications

3) No time specific task/Job would execute if app is not in the tray and many more ….

Solution

user needs to enable auto start in settings for app to keep background service/Job running.By default it is off.To do this in some of the devices we can use,

Sample code

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = new Intent();

    String manufacturer = android.os.Build.MANUFACTURER;

    switch (manufacturer) {

        case "xiaomi":
            intent.setComponent(new ComponentName("com.miui.securitycenter",
                    "com.miui.permcenter.autostart.AutoStartManagementActivity"));
            break;
        case "oppo":
            intent.setComponent(new ComponentName("com.coloros.safecenter",
                    "com.coloros.safecenter.permission.startup.StartupAppListActivity"));

            break;
        case "vivo":
            intent.setComponent(new ComponentName("com.vivo.permissionmanager",
                    "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
            break;
    }

  List<ResolveInfo> arrayList =  getPackageManager().queryIntentActivities(intent,
          PackageManager.MATCH_DEFAULT_ONLY);

    if (arrayList.size() > 0) {
        startActivity(intent);
    }
}

}

SOURCE: https://stackoverflow.com/questions/52849445/some-oreo-devices-are-not-getting-push-notification/52943903#52943903

like image 92
Mike Brian Olivera Avatar answered Oct 19 '22 14:10

Mike Brian Olivera


You can go to Settings>More settings>Permission management(Applications) > Autostart to turn on the app switch.

like image 24
Deskcode Solution Avatar answered Oct 19 '22 12:10

Deskcode Solution