简体   繁体   中英

Xiaomi does not receive notification when application is not running

I am working on an application where I am using Google Push Notification. Application receives notification when it is running in Xiaomi phone otherwise when it's killed it does not receive notification.

If we want to receive notification if application is killed then we need to allow auto restart app manually from security app of xiaomi. I want any trick to do this programmatically without asking user. Is there any way to do this ?

在此处输入图像描述

http://en.miui.com/thread-33826-1-1.html

There are five settings that needs to be done manually in case of xiaomi to properly run any application. I have done a lot of research on this and there's no way to fix these settings programmatically. These are the settings:

  1. Auto Start -> ON (Toggle and restart your app)
  2. MIUI Optimization under Developer Options -> OFF
  3. Memory Optimization under Developer Options -> LOW/OFF
  4. No restrictions on background activities under Battery & Performance Settings
  5. Battery Saver -> OFF

There are many other devices in which the manual settings needs to be done in order for the app to work as expected eg Lenovo, some Micromax devices. Companies impose these kind on restrictions on background activities to improve the overall battery life. Some apps like facebook and whatsapp work correctly as these might have been included as system apps.

After MIUI 6 & 7:

MIUI power saving mode is default set to "Standard" (Background access to the location services and the network will be restricted)

Where to set:

Settings -> Additional settings -> Battery & performance -> Manage apps battery usage -> Power Saving Modes -> Set to Off (MIUI won't restrict background activities)

As for my understanding once you clear apps or clear memory in Recent Apps menu, xiaomi (or MIUI rom) will force close all the services and memory related to that app similar to user going to settings and force stopping app ,

This Link talks about the same issue, hence all the Broadcast receivers and Services will be ended unless started by the user again, so the notification wont be received,

However you can try just enabling auto-start for your app permissions in settings and If it still doesn't work try creating service that restarts by itself and enable auto-start in the settings, AutoStart is very important in MIUI, untill its enabled all the notification or app activity will be force closed and will never start

I faced a similar issue and fixed it by adding a BOOT_COMPLETED receiver to my app.

Add following to manifest :

<receiver
    android:name=".receivers.BootReceiver"
    android:enabled="true">
    <intent-filter>
       <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

Then create your BootReceiver class

public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {

            Intent startServiceIntent = new Intent(context, FBTokenService.class);
            context.startService(startServiceIntent);

            Intent notificationServiceIntent = new Intent(context, FBNotificationService.class);
            context.startService(notificationServiceIntent);
        }
    }
}

It should work with this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM