Open app by package name

274 views
Skip to first unread message

Ger PG

unread,
Jun 29, 2015, 5:49:32 AM6/29/15
to tas...@googlegroups.com
Hello,

I am trying to open an app whose package name is stored in a variable. For example, the variable is %Player and it contains "com.soundcloud.android". I have tried the shell command "am start -m "Player" but nothing happens (both with and without using root).

What am I doing wrong?

Thank you very much in advance.

Robert Ryan

unread,
Jun 29, 2015, 1:49:20 PM6/29/15
to Support Forum

You can get the app name from the package name via Java:

Test (69)
A1: Java Function [ Return:(PackageManager) pacman Class Or Object:CONTEXT Function:getPackageManager
{PackageManager} () Param: Param: Param: Param: Param: Param: Param: ]
A2: Java Function [ Return:app_info Class Or Object:pacman Function:getApplicationInfo
{ApplicationInfo} (String, int) Param:net.dinglisch.android.taskerm Param:0 Param: Param: Param: Param: Param: ]
A3: Java Function [ Return:%label Class Or Object:app_info Function:loadLabel
{CharSequence} (PackageManager) Param:pacman Param: Param: Param: Param: Param: Param: ]
A4: Flash [ Text:%label Long:Off ]

Germán Piscitello

unread,
Jun 29, 2015, 4:04:24 PM6/29/15
to tas...@googlegroups.com
Hi! Thanks for your reply. In fact, I already know the package name, the only thing I want is to open it.


Germán Piscitello

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/fAVrfe_OYjw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Robert Ryan

unread,
Jun 29, 2015, 7:00:00 PM6/29/15
to Support Forum

Sorry, totally misread that. To launch an app using its package name:

Test (69)
A1: Java Function [ Return:(PackageManager) pacman Class Or Object:CONTEXT Function:getPackageManager
{PackageManager} () Param: Param: Param: Param: Param: Param: Param: ]

A2: Java Function [ Return:intent Class Or Object:pacman Function:getLaunchIntentForPackage
{Intent} (String) Param:uk.co.aifactory.chess Param: Param: Param: Param: Param: Param: ]
A3: Java Function [ Return: Class Or Object:CONTEXT Function:startActivity
{} (Intent) Param:intent Param: Param: Param: Param: Param: Param: ]

No root needed :)

Message has been deleted

Jay K

unread,
Jun 29, 2015, 10:15:53 PM6/29/15
to tas...@googlegroups.com
Great!
I was interested in this topic to launch an app with the package name only.
Thanks, Robert.
And I have a question, too.
Is there a way to know the package name (and class name) of the front app with java?

Robert Ryan

unread,
Jun 30, 2015, 1:52:45 AM6/30/15
to Support Forum

If you know the label of the top app, i.e. "Tasker" or "Chess", it can be done. It's  bit more complicated than the previous examples:

Test (69)
A1: Variable Set [ Name:%app_name To:Tasker Do Maths:Off Append:Off ]
A2: Variable Set [ Name:%package_name To:Not Found Do Maths:Off Append:Off ]
A3: Java Function [ Return:(PackageManager) pacman Class Or Object:CONTEXT Function:getPackageManager


{PackageManager} () Param: Param: Param: Param: Param: Param: Param: ]

A4: Java Function [ Return:app_list Class Or Object:pacman Function:getInstalledApplications
{List} (int) Param:128 Param: Param: Param: Param: Param: Param: ]
A5: Java Function [ Return:list_iterator Class Or Object:app_list Function:iterator
{Iterator} () Param: Param: Param: Param: Param: Param: Param: ]
A6: Java Function [ Return:%has_next Class Or Object:list_iterator Function:hasNext
{boolean} () Param: Param: Param: Param: Param: Param: Param: ]
<Find>
A7: Goto [ Type:Action Label Number:1 Label:End Find ] If [ %package_name !~ not found | %has_next !~ true ]
A8: Java Function [ Return:(ApplicationInfo) app_info Class Or Object:list_iterator Function:next
{Object} () Param: Param: Param: Param: Param: Param: Param: ]
A9: Java Function [ Return:%label Class Or Object:app_info Function:loadLabel
{CharSequence} (PackageManager) Param:pacman Param: Param: Param: Param: Param: Param: ]
A10: If [ %label ~ %app_name ]
A11: Java Function [ Return:cls Class Or Object:app_info Function:getClass
{Class} () Param: Param: Param: Param: Param: Param: Param: ]
A12: Java Function [ Return:fld Class Or Object:cls Function:getField
{java.lang.reflect.Field} (String) Param:processName Param: Param: Param: Param: Param: Param: ]
A13: Java Function [ Return:%package_name Class Or Object:fld Function:get
{Object} (Object) Param:app_info Param: Param: Param: Param: Param: Param: ]
A14: End If
A15: Goto [ Type:Action Label Number:1 Label:Find ]
<End Find>
A16: Anchor
A17: Flash [ Text:%package_name Long:Off ]

Jay K

unread,
Jun 30, 2015, 3:17:53 AM6/30/15
to tas...@googlegroups.com
Oh! There is a way.
Thanks again, Robert. It shows the package name correctly. Great!!!

Robert Ryan

unread,
Jun 30, 2015, 8:55:07 AM6/30/15
to Support Forum

Sorry, there is a bug in that. I should have updated %has_next before the last goto:

Test (69)
A1: Variable Set [ Name:%app_name To:AnalyzeThis Do Maths:Off Append:Off ]

A2: Variable Set [ Name:%package_name To:Not Found Do Maths:Off Append:Off ]
A3: Java Function [ Return:(PackageManager) pacman Class Or Object:CONTEXT Function:getPackageManager
{PackageManager} () Param: Param: Param: Param: Param: Param: Param: ]
A4: Java Function [ Return:app_list Class Or Object:pacman Function:getInstalledApplications
{List} (int) Param:128 Param: Param: Param: Param: Param: Param: ]
A5: Java Function [ Return:list_iterator Class Or Object:app_list Function:iterator
{Iterator} () Param: Param: Param: Param: Param: Param: Param: ]
A6: Java Function [ Return:%has_next Class Or Object:list_iterator Function:hasNext
{boolean} () Param: Param: Param: Param: Param: Param: Param: ]
<Find>
A7: Goto [ Type:Action Label Number:1 Label:End Find ] If [ %package_name !~ not found | %has_next !~ true ]
A8: Java Function [ Return:(ApplicationInfo) app_info Class Or Object:list_iterator Function:next
{Object} () Param: Param: Param: Param: Param: Param: Param: ]
A9: Java Function [ Return:%label Class Or Object:app_info Function:loadLabel
{CharSequence} (PackageManager) Param:pacman Param: Param: Param: Param: Param: Param: ]
A10: If [ %label ~ %app_name ]
A11: Java Function [ Return:cls Class Or Object:app_info Function:getClass
{Class} () Param: Param: Param: Param: Param: Param: Param: ]
A12: Java Function [ Return:fld Class Or Object:cls Function:getField
{java.lang.reflect.Field} (String) Param:processName Param: Param: Param: Param: Param: Param: ]
A13: Java Function [ Return:%package_name Class Or Object:fld Function:get
{Object} (Object) Param:app_info Param: Param: Param: Param: Param: Param: ]
A14: End If

A15: Java Function [ Return:%has_next Class Or Object:list_iterator Function:hasNext


{boolean} () Param: Param: Param: Param: Param: Param: Param: ]

A16: Goto [ Type:Action Label Number:1 Label:Find ]
<End Find>
A17: Anchor
A18: Flash [ Text:%package_name Long:Off ]

Jay K

unread,
Jun 30, 2015, 10:19:37 AM6/30/15
to tas...@googlegroups.com
That's OK, Robert.
I already caught the problem and solve it by moving the label 'Find' to A6.
Thanks for your kindness. :-)

2015년 6월 30일 화요일 오후 9시 55분 7초 UTC+9, Robert Ryan 님의 말:

Shane Mckay

unread,
Sep 30, 2015, 9:36:15 PM9/30/15
to Tasker
I used your method to get the label name into a Tasker menu but would like to know if you could help me get the labels for all the apps (apps = those that would appear in the Application Selection window if you add new profile in Tasker and tapped Application) and stored them in a variable array that can be used as the source for the Menu?

I could really use your help and would appreciate beyond what words could express! I opened a thread on Reddit (link below) which came up a little short in terms of populating the menu  but in essence I'm trying to have an app list menu pop up on long tap of a shortcut within a scene and store the user selection as the default target for said shortcut. It can be done using AutoLaunch, a non-free 3rd party dependency, which I'd prefer not to have to use.

https://www.reddit.com/r/tasker/comments/3mmi8k/question_is_it_possible_to_change_the_target_app/
Reply all
Reply to author
Forward
0 new messages