在HUAWEI和XIOMI设备中未调用onTaskRemoved() [英] onTaskRemoved() not getting called in HUAWEI and XIOMI devices
问题描述
我一直在Service中使用onTaskRemoved()
方法,通过将其从设备最近"列表中删除,来检测该应用何时被删除.我会执行一些日志记录以及发生这种情况时需要进行的其他一些操作.
效果很好.
I've been using onTaskRemoved()
method in a Service to detect when an app was removed from device RECENT list by swiping it away. I preform some logging and some other operations that need to take place when this happens.
It works perfectly.
然后我在运行Android 6.0的HUAWEI设备中检查了此方法. 该方法永远不会被调用.我还添加了一个Log.d调用,并且正如预期的那样,此日志从未出现.在XIOMI设备上也会发生同样的情况.
Then I checked this method in an HUAWEI device running Android 6.0. The method never gets called. I also added a Log.d call and as expected, this log never appeared. The same happens on a XIOMI device.
任何想法为什么会发生这种情况以及如何解决呢?还是有另一种方法可以检测出不依赖于onTaskRemoved()
的应用程序已从最近的列表中删除?
Any ideas why this happens and how to resolve this? Or is there another way to detect app was removed from RECENT list with out relying on onTaskRemoved()
?
谢谢
推荐答案
用户在小米设备上安装了应用程序后,将用户重定向到自动启动活动并告诉用户打开:
When user has installed your app on xiaomi device, redirect user to auto start activity and tell user to switch on:
if (Build.BRAND.equalsIgnoreCase("xiaomi")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent);
}
使用上面的代码在小米上启动自动启动活动页面
Use the above code to launch autostart activity page on xiaomi
这篇关于在HUAWEI和XIOMI设备中未调用onTaskRemoved()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!