简体   繁体   English

应用程序未运行时小米没有收到通知

[英]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:这些是设置:

  1. Auto Start -> ON (Toggle and restart your app)自动启动 -> 开启(切换并重新启动您的应用程序)
  2. MIUI Optimization under Developer Options -> OFF开发者选项->关闭MIUI优化
  3. Memory Optimization under Developer Options -> LOW/OFF开发者选项 -> 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.还有许多其他设备需要手动设置才能使应用程序按预期工作,例如联想、一些 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.

相关问题 Android | 针对您的应用程序运行测试时是否可能收到推送通知 - Android | Is it possible to receive a push notification when running test against your application 应用程序在 android 中终止时未收到通知 - Notification not receive when Application terminated in android 当应用程序未运行时,在 Android 手机上接收 FCM 数据通知 - Receive an FCM data notification on Android phone when app is not running 当我的应用程序收到通知时,打开屏幕背光 - Turn the screen backlight on when my application receive notification 通知样式在带有 Android 的小米手机上应用时的 RemoteServiceException 11 - RemoteServiceException when notification style is applied on Xiaomi phones with Android 11 如何在接收通知时在应用程序中打开mainview的webview - how to open webview of mainactivity in application, when receive notification 如何在Android聊天应用程序处于后台时接收消息作为通知 - How to receive message as notification when the android chat application is in background 如果未运行,注册了BroadcastReceiver的android应用程序会收到广播吗? - Does the android application that registered a BroadcastReceiver receive a broadcast if it is no running? 应用程序运行时不显示Firebase通知 - Firebase Notification Does Not Show When Application Run 如果已在运行应用程序,则在连接了USB附件时如何接收Intent - How to receive Intent when USB Accessory is attached if application is already running
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM