1

I am developing an application that has the ability to change the icon that is displayed in the launcher. I share the code that does this. I understand that this is not a forum for developers, so you can imagine that there are several icons in the application, but only one is always displayed in the launcher.

public static void setIcon(LauncherIcon icon) {
    Context ctx = ApplicationLoader.applicationContext;
    PackageManager pm = ctx.getPackageManager();
    for (LauncherIcon i : LauncherIcon.values()) {
        pm.setComponentEnabledSetting(i.getComponentName(ctx), i == icon ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }
}

I wanted to write a command that would know which icon is currently active. This can just be determined by taking from somewhere a list of only active activity-aliases. Since the control in the code happens through the PackageManager, I assume that in the terminal this is possible with the pm utility. But I didn't find anything to help me. As I understand it, somehow through pm I can get a list of activity-aliases, and then for each get the properties COMPONENT_ENABLED_STATE_ENABLED or COMPONENT_ENABLED_STATE_DISABLED , which I specify in the code. If I find the property COMPONENT_ENABLED_STATE_ENABLED then I should get the name of this activity-alias.

1 Answer 1

0

For example if your app has package com.company.Calc and has two activity-alias: com.company.MainActivity1 (default) and com.company.MainActivity2 you can get current active activity-alias like this:

dumpsys package com.company.Calc | grep -A1 "enabledComponents" | grep "com.company" | grep -o '[^$(printf '\t') ].*' || echo "com.company.MainActivity1"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .