[英]Xiaomi does not receive notification when application is not running
I am working on an application where I am using Google Push Notification.我正在开发一个使用 Google 推送通知的应用程序。 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 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:这些是设置:
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.还有许多其他设备需要手动设置才能使应用程序按预期工作,例如联想、一些 Micromax 设备。 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. facebook 和 whatsapp 等一些应用程序可以正常工作,因为这些应用程序可能已作为系统应用程序包含在内。
After MIUI 6 & 7: MIUI 6 & 7 之后:
MIUI power saving mode is default set to "Standard" (Background access to the location services and the network will be restricted) MIUI省电模式默认设置为“标准”(后台访问定位服务和网络将被限制)
Where to set:在哪里设置:
Settings -> Additional settings -> Battery & performance -> Manage apps battery usage -> Power Saving Modes -> Set to Off (MIUI won't restrict background activities)设置 -> 其他设置 -> 电池和性能 -> 管理应用程序电池使用 -> 省电模式 ->设置为关闭(MIUI 不会限制后台活动)
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 ,至于我的理解,一旦您在最近的应用程序菜单中清除应用程序或清除内存,小米(或 MIUI rom)将强制关闭与该应用程序相关的所有服务和内存,类似于用户进入设置并强制停止应用程序,
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但是,您可以尝试在设置中为您的应用程序权限启用自动启动,如果仍然不起作用,请尝试创建自行重启的服务并在设置中启用自动启动,自动启动在 MIUI 中非常重要,直到它全部启用通知或应用活动将被强制关闭并且永远不会启动
I faced a similar issue and fixed it by adding a BOOT_COMPLETED receiver to my app.我遇到了类似的问题,并通过在我的应用程序中添加一个 BOOT_COMPLETED 接收器来修复它。
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然后创建你的 BootReceiver 类
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.它应该适用于此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.