Xiaomi does not receive a notification when the application is not running

28.3k views Asked by At

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

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

Enter image description here

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

4

There are 4 answers

2
Nikhil Gupta On

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

Add the following to the 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.

0
Tony Yeh On

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)

0
AudioBubble On

From https://www.cricketbuddies.com/cricket/world-cricket-championship-2/guides/wcc2-guides, "Game Notification Fix" section:

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 e.g. 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.

9
Ujju On

As for my understanding, once you clear apps or clear memory in the 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 the 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 won’t 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 a service that restarts by itself and enable auto-start in the settings, AutoStart is very important in MIUI, until it’s enabled all the notification or app activity will be force closed and will never start.