简体   繁体   English

在小米,Oppo或Vivo手机上-应用程序任务无法按预期工作

[英]On Xiaomi or Oppo or Vivo phones - Application Task not working as expected

I have a small android application project (Used for a local community news app)on android, which is (or was) working on API 22 and onward. 我在android上有一个小型android应用程序项目(用于本地社区新闻应用程序),该项目正在(或正在)开发API 22及更高版本。 Only a issue recently came to our notice is that on Chinese phones like Xiaomi or Oppo or Vivo our notifications (tried both local/Firebase) are not working even when the application is white-listed. 我们最近才注意到的一个问题是,在小米,Oppo或Vivo之类的中国手机上,即使该应用程序已列入白名单,我们的通知(都在本地/ Firebase上都尝试过)也无法正常工作。

I see some suggestions on online blogs to use AlarmManager (but I guess this is bad idea - for real time notifications), not sure 我在在线博客上看到一些使用AlarmManager的建议(但我想这不是个好主意-实时通知),不确定

I have also tried trading on code like below, but still no luck 我也尝试过如下代码的交易,但还是没有运气

https://github.com/commonsguy/cw-omnibus/tree/v8.4/Notifications/Foreground https://github.com/commonsguy/cw-omnibus/tree/v8.4/Notifications/Foreground

What I've figured out is, if the app task is locked, it will be persisted and my app notification work. 我发现的是,如果应用程序任务被锁定,它将保持不变,并且我的应用程序通知将正常工作。

See the image below: 见下图:

在此处输入图片说明

How to programmatically achieve this? 如何以编程方式实现这一目标?

Can it be a single code (or module) for all the versions of Xiaomi or Oppo or Vivo (or say MiUI)? 它可以是小米,Oppo或Vivo(或说MiUI)所有版本的单个代码(或模块)吗?

Yes i also faced this problem, i have tried many given solutions in oppo and vivo mobiles but problem still not solved. 是的,我也遇到了这个问题,我在oppo和vivo手机上尝试了许多给定的解决方案,但问题仍然没有解决。

did you try onTaskRemoved() method in Service class? 您是否尝试过Service类中的onTaskRemoved()方法? when we swipe app or kill the app onTaskremoved() method is called instead of onDestroy() of Service class. 当我们滑动应用程序或杀死应用程序时,将调用onTaskremoved()方法而不是Service类的onDestroy()

So maybe there is a solution if we send a broadcast receiver in this method which restart the Service. 因此,如果我们以这种方法发送广播接收器以重新启动服务,则可能有解决方案。

And also look this thread also: 并且还要看这个线程:

How to enable auto start for my app in xiaomi programmatically 如何以编程方式在小米中为我的应用程序启用自动启动

Maybe it helps. 也许有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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