JacksOnF1re
JacksOnF1re

Reputation: 3547

Add multiple launcher shortcuts to app-menu in runtime

My question is not how to add a shortcut to the homescreen, I know how to achieve that, but I am to dumb to add programmaticaly a launcher shortcut to the app-menu of the smartphone in runtime.

Actually I need to add multiple shortcuts in runtime to the app-menu, which then all open one specific activity with different bundles. So not just adding launcher flag to the manifest.

Does anybody know if and how that is possible and can maybe provide some sources if not?

edit: Ok, maybe if nobody knows how to achieve that, maybe there is a way to change a launcher shortcuts label and iconImage programmatically in runtime? Again, App-menu, not homescreen.

edit2: An image of what I understand for App-Menu

enter image description here

Thanks for the help! Cheers.

Upvotes: 3

Views: 2090

Answers (2)

Gyebro
Gyebro

Reputation: 1521

If you restrict the types and amount of custom features, you could use activity aliases. But in this case you should bundle all custom labels and logos with your application, and create an alias for each pair. This could work if you have "generic" custom features like: "Favourites", "Friends", etc. and want to have an associated app icon.

All aliases should be defined in AndroidManifest.xml

<activity-alias
        android:name=".Alias0"
        android:label="@string/favourites"
        android:icon="@drawable/favourites"
        android:enabled="true"
        android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity-alias>

You can enable/disable aliases with

getPackageManager().setComponentEnabledSetting(
            new ComponentName(packagename, aliasname),
            enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);

Here is a demo I've put together: ActivityAliases

See app icons starting with "Amazing"

Note: Updated aliases may take some time to appear in the app drawer depending on your launcher!

Upvotes: 3

Michael Alan Huff
Michael Alan Huff

Reputation: 3512

I am fairly sure that this can't be done.

The App-menu is exactly that, a menu for apps. This means that unless you want to go installing different apps, they won't show up there. More explicitly you cannot have something that isn't an app show up in the app menu.

However, if one did want to install other apps, this is possible with an intent that launches a Play Store link or an already downloaded .apk as seen here: Install Application programmatically on Android. Be very careful if you are going to try to install a package locally however. Facebook tried this long ago and was temporarily disabled in the Play Store at one point due to it "Breaking terms of service" by programmatically modifying itself and it's other "apps" without going through the app store. As noted in a comment thread here Can an Android app install another android app?

This use case you are speaking of is precisely why shortcuts were made in android.

Shortcuts are a different creature all together and, as you noted, can be created at runtime.

Here is a good article on shortcuts and their usage: http://phandroid.com/2014/03/15/android-101-shortcuts/

And here is a SO answer that demonstrates how to set custom text and icons for a shortcut. How to change an application icon programmatically in Android? Hope this helps!

Upvotes: 4

Related Questions