oppo, vivo app kill notification not coming in and

2020-03-24 09:43发布

问题:

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.

回答1:

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



回答2:

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