onTaskRemoved() 未在华为和小米设备中调用 [英] onTaskRemoved() not getting called in HUAWEI and XIAOMI devices
问题描述
我一直在服务中使用 onTaskRemoved()
方法来检测应用程序何时从设备 RECENT 列表中通过将其滑开来检测.发生这种情况时,我会执行一些日志记录和其他一些需要进行的操作.它完美运行.
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的华为设备上检查了这个方法.该方法永远不会被调用.我还添加了一个 Log.d 调用,正如预期的那样,这个日志从未出现过.小米设备也是如此.
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 XIAOMI 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()
?
谢谢
推荐答案
当用户在小米设备上安装了你的应用后,重定向用户到自动启动 Activity 并告诉用户开启:
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
这篇关于onTaskRemoved() 未在华为和小米设备中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!