Set Default Android Launcher on Huawei devices?

此生再无相见时 提交于 2020-02-29 04:23:13

问题


My Goal is here is to set my app as default launcher on Huawei devices.

1 - Explanations:

1.1 - Current situation:

I am already able to:

  • Check if my app is the default launcher
  • Display the 'launcher picker' (with the 'use once' / 'always' choice)

This all works fine.. except on Huawei devices!

From my point of view, Huawei's Android flavor does not properly 'honor' the "ACTION_MANAGE_DEFAULT_APPS_SETTINGS" intent action contract.

// this displays the list of default apps on all tested devices, except on Huawei devices!
// instead, it does display apps permissions, app links and apps'advanced settings
intent.setAction(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
activity.startActivity(intent);

As a B Plan, I am able to display the 'Applications & Notifications' settings 'page' using this:

String packageName = "com.android.settings";
String className = "Settings$AppAndNotificationDashboardActivity";
intent.setClassName(packageName, packageName + "." + className);
activity.startActivity(intent);

So the user can navigate from there, pressing this sequence of menu items:

  • -> Advanced Parameters ( expandable menu item : not present on tablet, and not sure it's present on phone)
  • -> Default Apps
  • -> Default Launcher

This requires 2 or 3 steps that I would like to avoid.

1.2 - This can be improved!

I found out that when the "-> Default Apps" menu item is selected, a (com.android.settings, .SubSettings) Intent (with extra) is launched but I was not able to make this works (permission denial).

But I installed Nova Launcher and it turns out it's able to display the "-> Default Apps" settings page on Huawei devices!
So the user land on a page where she/he only has to tap on "-> Default Launcher" then choose a default launcher: much easier.

2 - Questions:

As I think it's just not possible to display the 'Lancher Picker' on Huawei devices, here is my question:
How can I display the "-> Default Apps" settings page (image down here) on Huawei devices (like Nova Launcher does)?
Are they using another intent action on Huawei devices?

Thanks beforehand your help.


回答1:


Yes on Huawei devices, Nova uses a different intent to open to the correct screen. I likely found this by using apktool on the Settings.apk pulled from a Huawei device and looking at the AndroidManifest. Note that "com.android" is always a code smell as it means it's not part of the public API. Also this isn't even really "com.android" as it doesn't exist on AOSP and com.android.settings.PREFERRED_SETTINGS is purely a Huawei invention. It's very likely that some Huawei devices won't have this at all. It's also possible that in the future this intent might continue to work but not do what it currently does. So handle it carefully.

/* Some Huawei devices don't let us reset normally, handle it by opening preferred apps */
Intent preferredApps = new Intent("com.android.settings.PREFERRED_SETTINGS");
preferredApps.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
if (pm.resolveActivity(preferredApps, 0) != null) {
    context.startActivity(preferredApps);
} else {
    ...
}


来源:https://stackoverflow.com/questions/54059614/set-default-android-launcher-on-huawei-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!