Do not receive GCM notifications as soon as the application is killed on Xiaomi and Lenovo Android devices

Can someone help me get notifications about Xiaomi and Lenovo devices even after the application is killed (no more in the background)?

Change 1

I added the GCM radio receiver. Here is the code

inside AndroidManifest.xml

 <receiver
       android:name="com.don.offers.broadcast_receiver.GcmBroadcastReceiver"
       android:permission="com.google.android.c2dm.permission.SEND" >
       <intent-filter>
           <!-- Receives the actual messages. -->
           <action android:name="com.google.android.c2dm.intent.RECEIVE" />
           <category android:name="com.google.android.gcm.demo.app" />
       </intent-filter>
   </receiver>

GcmBroadcastReceiver.java

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        ComponentName comp = new ComponentName(context.getPackageName(),
                RegistrationIntentService.class.getName());
        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }
}

He solved my problem on an MI device, but not on Lenovo devices.

thank

+4
source share
2 answers

Lenovo mobile phones use Background Task Killer to terminate background applications to hide the task killer by banning the ban on the application menu

+1

MIUI , :

 private void addAppToAutoStartList() {
  AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
  alertDialogBuilder.setTitle("Warning!");
  alertDialogBuilder.setMessage("Please add this app to the Auto Start list of your device for better performance.");
  alertDialogBuilder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
   @Override public void onClick(DialogInterface dialogInterface, int i) {
    dialogInterface.dismiss();
    try {
     AppPreferences.getInstance(HomeActivity.this).setMiSpecialSetting(true);
     Intent intent = new Intent();
     intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
     startActivity(intent);
    } catch (Exception e) {
     Toast.makeText(HomeActivity.this, "Unable to add!", Toast.LENGTH_SHORT).show();
    }
   }
  });
  alertDialogBuilder.setNegativeButton("Ignore", new DialogInterface.OnClickListener() {
   @Override public void onClick(DialogInterface dialog, int arg1) {
    dialog.dismiss();
   }
  });
  AlertDialog alertDialog = alertDialogBuilder.create();
  alertDialog.show();
 }  

,

if(android.os.Build.MANUFACTURER.equalsIgnoreCase("xiaomi")) { addAppToAutoStartList(); 
}

: 1. , , push- - . 2. , , , , , , 1 2 , . MIUI . Xiaomi, 5-7 , .

0

Source: https://habr.com/ru/post/1670043/


All Articles