3

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.

JacksOnF1re
  • 3,336
  • 24
  • 55
  • why do you need to add multiple shortcuts at runtime, and not statically in the manifest? you will need multiple launcher activities in order to have multiple entry points, hence shortcuts. – Goran Horia Mihail Dec 08 '14 at 15:55
  • Because I will/want to provide the functionallity to the user to add different launchers, with custom names and logos. Yes, I actually thought about adding various launcher activities to the manifest and changing label, name and visibility in runtime. That's why I edited my question. The visibility is no problem, but I am still not able to change name and logo. – JacksOnF1re Dec 08 '14 at 16:07
  • 1
    AFAIK you can't. What you can do is put various activity (or activity-alias) definitions in your manifest that can be enabled/disabled in code. If you want to change the labels and icons arbitrarily the user needs to have an alternative launcher (or disassemble the apk and rebuild it). – Emanuel Moecklin Dec 12 '14 at 17:11
  • Hmm, I thought about to rebuild the apk, too. And actually there are some resources (thesis etc.), which descripe the process. But, unfortunately, they all claim that it is not possible to change the launcher shortcuts/labels in the app-menu, once installed. It is maybe possible to use an own custom launcher, but this would be to much overhead. The enabling/disabling did I mention, too - but because I don't known the apps I want to start before the install, this is not an option. Thanks for the answer! – JacksOnF1re Dec 12 '14 at 18:27
  • I am still seeking for an answer. – JacksOnF1re Dec 17 '14 at 14:12
  • I think there is a barrier of language here. What exactly do you mean by App-menu? Could you provide a screenshot? – Michael Alan Huff Dec 17 '14 at 19:04
  • @ Michael Alan Huff, maybe you're right. Sure I add one to the question. – JacksOnF1re Dec 17 '14 at 20:56

2 Answers2

4

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!

Community
  • 1
  • 1
Michael Alan Huff
  • 3,462
  • 3
  • 28
  • 44
  • I really appreciate your opinion and answer and moreover, thanks for the links. Although I known how to add custom shortcuts. Maybe, because you mentioned it, I would like to see something to install an application out of another in runtime (even with a user dialog). As said, I don't mind if the a solution to my question would be kind of fragile. (Like the custom shortcuts are anyway) – JacksOnF1re Dec 17 '14 at 21:00
  • No problem JacksOnF1re. I updated my answer to reflect your comment. – Michael Alan Huff Dec 17 '14 at 21:12
  • 1
    I am very puzzled, whom of you both I should give the reputation, because they both indicate that you really thought about your answer. I will set this answer to most helpful, because I already know the alias possibility and the option to install an application out of another gave me a hint into another direction. And that is why, I think it is worth the 50 reputation. Doesn't sound much, but it's about 25% of mine. Therefore, thank you both, even if to say thank you is uncommen here. If this will solve my problem, I'll set it to correct answer, too. – JacksOnF1re Dec 18 '14 at 11:00
3

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!

Gyebro
  • 1,511
  • 13
  • 19
  • I found out this solution, too and I am going think that this is the most you can do (unrooted). But unfortunately, although the answer is great, it doesn't solve my problem, because I can't use 'generic' aliases. Unless you have an idea to change the label and icon in runtime? – JacksOnF1re Dec 18 '14 at 10:39