2

I am using FCM push notification for start service in background mode but the app will not be getting any notification after killing the app. and I'm facing this problem in only vivo device. In other devices, it is working fine.

when i manually enable auto start then it will working fine. but without enable auto starts it will not working.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    Intent intent = new Intent(ACTION_MAIN);
    intent.setClass(this, LinphoneService.class);
    intent.putExtra("PushNotification", true);
    startForegroundService(intent);

} else {
    Intent intent = new Intent(ACTION_MAIN);
    intent.setClass(this, LinphoneService.class);
    intent.putExtra("PushNotification", true);
    startService(intent);
}

I need to start my service whenever app gets firebase push notification in all devices without enabling auto-start.

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60

1 Answers1

4

(1) Vivo and other chinese OEM's (Xiaomi, Oppo, Mi ) restrict background tasks. - Specially for Android 9 onwards.

As of now, enabling auto-start is the only option. You can prompt the user for auto start permission , take him to the settings page and request him to enable auto-start. Check this SO answer.

(2) System dialog for ignoring battery optimisation

Check security concerns here : By default battery optimisation is enabled for all apps above marshmallow.

https://commonsware.com/blog/2015/11/11/google-anti-trust-issues.html

You might want to prompt user to disable battery optimisations to let the app perform your tasks in background

Mayuri Khinvasara
  • 1,437
  • 1
  • 16
  • 12
  • I have managed background task in all OEM's expect vivo without enable auto-start. my background service is working fine in oppo, xiaomi devices without enable auto-start. but just problem in vivo device because of i'm not getting firebase push notification after kill app in only vivo device. – Mayur Viras Sep 09 '19 at 04:39