Android Question Launch shortcut from external application

plager

Member
Hello comunity,
I am struggling to launch shortcut created from different application.
Consider this:
I am using hermit app to create a desktop shortcuts. (it is an app for creating 'lite web apps') https://play.google.com/store/apps/details?id=com.chimbori.hermitcrab
I created a shortcut for a page 'https://www.csfd.cz'. It has been added to a desktop and it works correctly.. I am using square home as a launcher. It is able to export all its data, so I did it and found shortcut to csfd page from hermit app. It looks like this (it is a part of json dump from square home backup):
"com.chimbori.hermitcrab\/.AdminActivity","i":"www.csfd.cz-124a8b28"

Now, my question is: how do I launch this shortcut from within my app?
I am not going to describe all my attempts, that's really not neccessary. I tried launching intent, putting extras, settings components to intent, adding external activity to manifest, tried chatGPT. No luck at all, only error messages form 'no activity to handle' to 'activity not found exception'... Fighting with this for about 4 hours now and still no luck :(

Would anyone be so kind to give me a method or technique how to achieve this?
 
Solution
It has been a long struggle. I achieved a solution. Maybe it will help someone:
B4X:
    Dim pm As PackageManager
    Dim StartIntent As Intent = pm.GetApplicationIntent("com.chimbori.hermitcrab")
    'Log(StartIntent)
    ' (Intent) Intent {
    '        act=android.intent.action.MAIN
    '        cat=[android.intent.category.LAUNCHER]
    '        flg=0x10000000
    '        pkg=com.chimbori.hermitcrab
    '        cmp=com.chimbori.hermitcrab/.AdminActivity
    '    }

    'StartIntent.SetComponent("com.chimbori.hermitcrab/.WebActivity")        ' activity not found exception
    'StartIntent.SetComponent("com.chimbori.hermitcrab/.webactivity")        ' activity not found exception...

plager

Member
Okay, maybe I was too specific. Anybody can help me with launching any shortcut from any external app?

Thanks for your time, folks.

























Thanks
 
Upvote 0

plager

Member
Thank you, Erel, for the answer. Your solution obviously works, but hermit browser is much more powerful than usual webview. So I'd like to know how to launch shortcut from within my app, if it is even possible. Thanks ;)
 
Upvote 0

plager

Member
It has been a long struggle. I achieved a solution. Maybe it will help someone:
B4X:
    Dim pm As PackageManager
    Dim StartIntent As Intent = pm.GetApplicationIntent("com.chimbori.hermitcrab")
    'Log(StartIntent)
    ' (Intent) Intent {
    '        act=android.intent.action.MAIN
    '        cat=[android.intent.category.LAUNCHER]
    '        flg=0x10000000
    '        pkg=com.chimbori.hermitcrab
    '        cmp=com.chimbori.hermitcrab/.AdminActivity
    '    }

    'StartIntent.SetComponent("com.chimbori.hermitcrab/.WebActivity")        ' activity not found exception
    'StartIntent.SetComponent("com.chimbori.hermitcrab/.webactivity")        ' activity not found exception
    'StartIntent.SetComponent("com.chimbori.hermitcrab/.AdminActivity")        ' this does nothing (no error, but won't start desired shortcut, only main app
    'StartIntent.SetComponent("com.chimbori.hermitcrab/.adminactivity")        ' activity not found exception. activity name is apparently case sensitive.
    'StartIntent.SetComponent("com.chimbori.hermitcrab/.browseractivity")    ' activity not found exception.
    StartIntent.SetComponent("com.chimbori.hermitcrab/.BrowserActivity")    ' it works!!!
    StartIntent.PutExtra("key","www.csfd.cz-124a8b28")
    StartActivity(StartIntent)

Being doing trial and error, so many attempts within two or three days.
To generalize steps:
- get a real activity of target app. In my first post I was wrong - desired activity was not AdminActivity, but BrowserActivity. This activity must be set as component via intent.SetComponent()
- desired argument must be included as PutExtra. In my case this argument is called 'key'. Name of argument is case sensitive (at least in hermit app, so 'KeY' won't work). Argument value is clear - it is a string given by hermit app.

This should work on every app which accepts arguments - similar to windows programming logic: 'some_exe_file.exe arg1_name arg1_value arg2_name arg2_value etc...'
It has some limitations as described here:
Only main activities—activities that handle the Intent.ACTION_MAIN action and the Intent.CATEGORY_LAUNCHER category—can have shortcuts. If an app has multiple main activities, define the set of shortcuts for each activity.
 
Upvote 0
Solution
Top