Launch app from Package Name only

1,106 views
Skip to first unread message

Rajat R

unread,
Jul 4, 2014, 5:45:50 AM7/4/14
to tas...@googlegroups.com
In my task I have the package name of an app in a variable (this app can keep changing), and I need to be able to launch the app from a Tasker command.

- I have tried sending Intents, but they only seem to work if I fill the Class field as well. This isn't viable for me as the class will keep on changing for different apps and unless there's a programmable way to automatically extract the Main Activity class for the target app, it won't work.

- I tried the shell script method (am start), but it also needs the Main Activity Class.

I'm surely missing something, please help.

Thank you

Matt R

unread,
Jul 4, 2014, 12:12:41 PM7/4/14
to tas...@googlegroups.com
I think the autolaunch plugin can do that.

Matt

Rajat

unread,
Jul 4, 2014, 12:21:16 PM7/4/14
to tas...@googlegroups.com
​​
Correct me if I'm wrong though, but doesn't it have an app number limitation? I don't have an extensive use planned to justify buying it.
Also, is there no direct way in Tasker to get the launcher intent of an app? The one that gets launched by default when its icon is clicked in app drawer.



On Fri, Jul 4, 2014 at 9:42 PM, Matt R <matthew.r...@gmail.com> wrote:
I think the autolaunch plugin can do that.

Matt

--
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/JYhkyVXHWOs/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.

Rajat R

unread,
Jul 4, 2014, 12:21:25 PM7/4/14
to tas...@googlegroups.com
​​
Correct me if I'm wrong though, but doesn't it have an app number limitation? I don't have an extensive use planned to justify buying it.
Also, is there no direct way in Tasker to get the launcher intent of an app? The one that gets launched by default when its icon is clicked in app drawer.

Matt R

unread,
Jul 4, 2014, 12:54:27 PM7/4/14
to tas...@googlegroups.com
You can do a run shell action with command

am start -a android.intent.action.MAIN your.package.name

Matt

Pent

unread,
Jul 4, 2014, 1:07:25 PM7/4/14
to tas...@googlegroups.com
You can't just launch 'a package'. You have to specify which activity within the package.

A package could e.g. have two activities which should appear in the launcher, there isn't necessarily
a 'main' activity.

To do what you're wanting, Tasker would need some extra features, i.e. being able to list components
in a package and query things about them.

Pent

Rajat R

unread,
Jul 4, 2014, 1:16:10 PM7/4/14
to tas...@googlegroups.com
@Matt
Yes I tried that with several apps but it didn't work. Example:
am start -a android.intent.action.MAIN com.android.calculator2

@Pent
I guess your answer settles it then, it isn't possible what I'm trying to achieve. I did think of those apps with 2 icons in launchers but figured they are rare and might not be much of an issue if there's a default MainActivity I could target.

Matt R

unread,
Jul 4, 2014, 2:01:05 PM7/4/14
to tas...@googlegroups.com
Weird. It works, but only as root. Without root, it gives the error about needing "interact across users full" permission.

Matt

Rajat

unread,
Jul 4, 2014, 2:09:02 PM7/4/14
to tas...@googlegroups.com
Wow, really? You were successful with the calculator command I added earlier? I just turned on Root but didn't have success. Tried with another app too.
It didn't give an error either, just the 'Text relocations, memory wasted' warning.



On Fri, Jul 4, 2014 at 11:31 PM, Matt R <matthew.r...@gmail.com> wrote:
Weird. It works, but only as root. Without root, it gives the error about needing "interact across users full" permission.

Matt

Matt R

unread,
Jul 4, 2014, 2:18:36 PM7/4/14
to tas...@googlegroups.com
Yes, it worked with root checked. Do you have root?

Matt

Rajat

unread,
Jul 4, 2014, 2:45:11 PM7/4/14
to tas...@googlegroups.com
Surely. That's the first thing I do on a new phone.
Do you see anything odd with the command here?
https://docs.google.com/file/d/0B9Bg_GtAO8DTbEpDYVRMXzUtZmM/edit


On Fri, Jul 4, 2014 at 11:48 PM, Matt R <matthew.r...@gmail.com> wrote:
Yes, it worked with root checked. Do you have root?

Matt

Matt R

unread,
Jul 4, 2014, 3:09:42 PM7/4/14
to tas...@googlegroups.com
Nope. Hmm ... I wouldn't think it would be device-dependent, but I guess it is? What's the text of the output that you were mentioning?

Matt

Rajat

unread,
Jul 4, 2014, 3:20:43 PM7/4/14
to tas...@googlegroups.com
Device dependent... that's highly unlikely. I'm using a Nexus 5 with rooted stock ROM and custom kernel.
Here's the warning:
WARNING: linker: app_process has text relocations. This is wasting memory and is a security risk. Please fix.WARNING: linker: app_process has text relocations. This is wasting memory and is a security risk. Please fix.Error: Activity not started, unable to resolve Intent { act=android.intent.action.MAIN com.android.calculator2 flg=0x10000000 }

Though the command itself didn't seem to have failed, the STD_OUT was 0 (the var to 'Store Result in').


On Sat, Jul 5, 2014 at 12:39 AM, Matt R <matthew.r...@gmail.com> wrote:
Nope. Hmm ... I wouldn't think it would be device-dependent, but I guess it is? What's the text of the output that you were mentioning?

Matt

Matt R

unread,
Jul 4, 2014, 4:33:02 PM7/4/14
to tas...@googlegroups.com
Maybe a change in android? I'm still on 4.2. What's your output from just the am command? Mine says:

_________________________________

usage: am [subcommand] [options]
usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]
[--R COUNT] [-S] [--opengl-trace]
[--user <USER_ID> | current] <INTENT>
am startservice [--user <USER_ID> | current] <INTENT>
am force-stop [--user <USER_ID> | all | current] <PACKAGE>
am kill [--user <USER_ID> | all | current] <PACKAGE>
am kill-all
am broadcast [--user <USER_ID> | all | current] <INTENT>
am instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w]
[--user <USER_ID> | current]
[--no-window-animation] <COMPONENT>
am profile start [--user <USER_ID> current] <PROCESS> <FILE>
am profile stop [--user <USER_ID> current] [<PROCESS>]
am dumpheap [--user <USER_ID> current] [-n] <PROCESS> <FILE>
am set-debug-app [-w] [--persistent] <PACKAGE>
am clear-debug-app
am monitor [--gdb <port>]
am screen-compat [on|off|wvga|get] <PACKAGE>
am display-size [reset|WxH]
am display-density [reset|DENSITY]
am to-uri [INTENT]
am to-intent-uri [INTENT]
am switch-user <USER_ID>
am stop-user <USER_ID>

am start: start an Activity. Options are:
-D: enable debugging
-W: wait for launch to complete
--start-profiler <FILE>: start profiler and send results to <FILE>
-P <FILE>: like above, but profiling stops when app goes idle
-R: repeat the activity launch <COUNT> times. Prior to each repeat,
the top activity will be finished.
-S: force stop the target app before starting the activity
--opengl-trace: enable tracing of OpenGL functions
--user <USER_ID> | current: Specify which user to run as; if not
specified then run as the current user.

am startservice: start a Service. Options are:
--user <USER_ID> | current: Specify which user to run as; if not
specified then run as the current user.

am force-stop: force stop everything associated with <PACKAGE>.
--user <USER_ID> | all | current: Specify user to force stop;
all users if not specified.

am kill: Kill all processes associated with <PACKAGE>. Only kills.
processes that are safe to kill -- that is, will not impact the user
experience.
--user <USER_ID> | all | current: Specify user whose processes to kill;
all users if not specified.

am kill-all: Kill all background processes.

am broadcast: send a broadcast Intent. Options are:
--user <USER_ID> | all | current: Specify which user to send to; if not
specified then send to all users.

am instrument: start an Instrumentation. Typically this target <COMPONENT>
is the form <TEST_PACKAGE>/<RUNNER_CLASS>. Options are:
-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with
[-e perf true] to generate raw output for performance measurements.
-e <NAME> <VALUE>: set argument <NAME> to <VALUE>. For test runners a
common form is [-e <testrunner_flag> <value>[,<value>...]].
-p <FILE>: write profiling data to <FILE>
-w: wait for instrumentation to finish before returning. Required for
test runners.
--user <USER_ID> | current: Specify user instrumentation runs in;
current user if not specified.
--no-window-animation: turn off window animations will running.

am profile: start and stop profiler on a process. The given <PROCESS> argument
may be either a process name or pid. Options are:
--user <USER_ID> | current: When supplying a process name,
specify user of process to profile; uses current user if not specified.

am dumpheap: dump the heap of a process. The given <PROCESS> argument may
be either a process name or pid. Options are:
-n: dump native heap instead of managed heap
--user <USER_ID> | current: When supplying a process name,
specify user of process to dump; uses current user if not specified.

am set-debug-app: set application <PACKAGE> to debug. Options are:
-w: wait for debugger when application starts
--persistent: retain this value

am clear-debug-app: clear the previously set-debug-app.

am bug-report: request bug report generation; will launch UI
when done to select where it should be delivered.
am monitor: start monitoring for crashes or ANRs.
--gdb: start gdbserv on the given port at crash/ANR

am screen-compat: control screen compatibility mode of <PACKAGE>.

am display-size: override display size.

am display-density: override display density.

am to-uri: print the given Intent specification as a URI.

am to-intent-uri: print the given Intent specification as an intent: URI.

am switch-user: switch to put USER_ID in the foreground, starting
execution of that user if it is currently stopped.

am stop-user: stop execution of USER_ID, not allowing it to run any
code until a later explicit switch to it.

<INTENT> specifications include these flags and arguments:
[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
[--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
[--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
[-n <COMPONENT>] [-f <FLAGS>]
[--grant-read-uri-permission] [--grant-write-uri-permission]
[--debug-log-resolution] [--exclude-stopped-packages]
[--include-stopped-packages]
[--activity-brought-to-front] [--activity-clear-top]
[--activity-clear-when-task-reset] [--activity-exclude-from-recents]
[--activity-launched-from-history] [--activity-multiple-task]
[--activity-no-animation] [--activity-no-history]
[--activity-no-user-action] [--activity-previous-is-top]
[--activity-reorder-to-front] [--activity-reset-task-if-needed]
[--activity-single-top] [--activity-clear-task]
[--activity-task-on-home]
[--receiver-registered-only] [--receiver-replace-pending]
[--selector]
[<URI> | <PACKAGE> | <COMPONENT>]

_________________________________

So you can see at the end it takes the unspecified input as either a URI, a package, or a component.

Matt

Rajat

unread,
Jul 4, 2014, 10:20:21 PM7/4/14
to tas...@googlegroups.com
I'm sorry I fell asleep after my last message, it was pretty late here.

I'm on 4.4.4 and below is my command output, not sure what I should be looking for in here though:


usage: am [subcommand] [options]
usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]
               [--R COUNT] [-S] [--opengl-trace]
               [--user <USER_ID> | current] <INTENT>
       am startservice [--user <USER_ID> | current] <INTENT>
       am stopservice [--user <USER_ID> | current] <INTENT>

       am force-stop [--user <USER_ID> | all | current] <PACKAGE>
       am kill [--user <USER_ID> | all | current] <PACKAGE>
       am kill-all
       am broadcast [--user <USER_ID> | all | current] <INTENT>
       am instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w]
               [--user <USER_ID> | current]
               [--no-window-animation] <COMPONENT>
       am profile start [--user <USER_ID> current] <PROCESS> <FILE>
       am profile stop [--user <USER_ID> current] [<PROCESS>]
       am dumpheap [--user <USER_ID> current] [-n] <PROCESS> <FILE>
       am set-debug-app [-w] [--persistent] <PACKAGE>
       am clear-debug-app
       am monitor [--gdb <port>]
       am hang [--allow-restart]
       am restart
       am idle-maintenance
       am screen-compat [on|off] <PACKAGE>

       am to-uri [INTENT]
       am to-intent-uri [INTENT]
       am switch-user <USER_ID>
       am stop-user <USER_ID>
       am stack create <TASK_ID> <RELATIVE_STACK_BOX_ID> <POSITION> <WEIGHT>
       am stack movetask <TASK_ID> <STACK_ID> [true|false]
       am stack resize <STACK_ID> <WEIGHT>
       am stack boxes
       am stack box <STACK_BOX_ID>


am start: start an Activity.  Options are:
    -D: enable debugging
    -W: wait for launch to complete
    --start-profiler <FILE>: start profiler and send results to <FILE>
    -P <FILE>: like above, but profiling stops when app goes idle
    -R: repeat the activity launch <COUNT> times.  Prior to each repeat,
        the top activity will be finished.
    -S: force stop the target app before starting the activity
    --opengl-trace: enable tracing of OpenGL functions
    --user <USER_ID> | current: Specify which user to run as; if not
        specified then run as the current user.

am startservice: start a Service.  Options are:
    --user <USER_ID> | current: Specify which user to run as; if not
        specified then run as the current user.

am stopservice: stop a Service.  Options are:

    --user <USER_ID> | current: Specify which user to run as; if not
        specified then run as the current user.

am force-stop: force stop everything associated with <PACKAGE>.
    --user <USER_ID> | all | current: Specify user to force stop;
        all users if not specified.

am kill: Kill all processes associated with <PACKAGE>.  Only kills.
  processes that are safe to kill -- that is, will not impact the user
  experience.
    --user <USER_ID> | all | current: Specify user whose processes to kill;
        all users if not specified.

am kill-all: Kill all background processes.

am broadcast: send a broadcast Intent.  Options are:
    --user <USER_ID> | all | current: Specify which user to send to; if not
        specified then send to all users.
    --receiver-permission <PERMISSION>: Require receiver to hold permission.


am instrument: start an Instrumentation.  Typically this target <COMPONENT>
  is the form <TEST_PACKAGE>/<RUNNER_CLASS>.  Options are:
    -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT).  Use with
        [-e perf true] to generate raw output for performance measurements.
    -e <NAME> <VALUE>: set argument <NAME> to <VALUE>.  For test runners a
        common form is [-e <testrunner_flag> <value>[,<value>...]].
    -p <FILE>: write profiling data to <FILE>
    -w: wait for instrumentation to finish before returning.  Required for
        test runners.
    --user <USER_ID> | current: Specify user instrumentation runs in;
        current user if not specified.
    --no-window-animation: turn off window animations while running.


am profile: start and stop profiler on a process.  The given <PROCESS> argument
  may be either a process name or pid.  Options are:
    --user <USER_ID> | current: When supplying a process name,
        specify user of process to profile; uses current user if not specified.

am dumpheap: dump the heap of a process.  The given <PROCESS> argument may
  be either a process name or pid.  Options are:
    -n: dump native heap instead of managed heap
    --user <USER_ID> | current: When supplying a process name,
        specify user of process to dump; uses current user if not specified.

am set-debug-app: set application <PACKAGE> to debug.  Options are:
    -w: wait for debugger when application starts
    --persistent: retain this value

am clear-debug-app: clear the previously set-debug-app.

am bug-report: request bug report generation; will launch UI
    when done to select where it should be delivered.

am monitor: start monitoring for crashes or ANRs.
    --gdb: start gdbserv on the given port at crash/ANR

am hang: hang the system.
    --allow-restart: allow watchdog to perform normal system restart

am restart: restart the user-space system.

am idle-maintenance: perform idle maintenance now.


am screen-compat: control screen compatibility mode of <PACKAGE>.

am to-uri: print the given Intent specification as a URI.

am to-intent-uri: print the given Intent specification as an intent: URI.

am switch-user: switch to put USER_ID in the foreground, starting
  execution of that user if it is currently stopped.

am stop-user: stop execution of USER_ID, not allowing it to run any
  code until a later explicit switch to it.

am stack create: create a new stack relative to an existing one.
   <TASK_ID>: the task to populate the new stack with. Must exist.
   <RELATIVE_STACK_BOX_ID>: existing stack box's id.
   <POSITION>: 0: before <RELATIVE_STACK_BOX_ID>, per RTL/LTR configuration,
               1: after <RELATIVE_STACK_BOX_ID>, per RTL/LTR configuration,
               2: to left of <RELATIVE_STACK_BOX_ID>,
               3: to right of <RELATIVE_STACK_BOX_ID>,               4: above <RELATIVE_STACK_BOX_ID>, 5: below <RELATIVE_STACK_BOX_ID>
   <WEIGHT>: float between 0.2 and 0.8 inclusive.

am stack movetask: move <TASK_ID> from its current stack to the top (true) or   bottom (false) of <STACK_ID>.

am stack resize: change <STACK_ID> relative size to new <WEIGHT>.

am stack boxes: list the hierarchy of stack boxes and their contents.

am stack box: list the hierarchy of stack boxes rooted at <STACK_BOX_ID>.

Matt

Matt R

unread,
Jul 5, 2014, 3:29:01 AM7/5/14
to tas...@googlegroups.com
Seems like your am command is a little different and yours unfortunately doesn't have any details on what the <intent> can include. Not sure how to help without the same am command.

Matt

Rajat

unread,
Jul 5, 2014, 4:04:21 AM7/5/14
to tas...@googlegroups.com

Good news and Bad news.
Good is that I found an app that does what I was trying to accomplish here through Tasker.
Bad is that it sucks and is very frustrating coming across a roadblock that doesn't budge while trying to do something seemingly simple. Guess it is one of those.
Thank you Matt for your patience and help, much appreciated.

ps If you feel curious about the whole purpose I was after, here's a link: http://forum.xda-developers.com/google-nexus-5/help/app-to-defrost-run-freeze-apps-t2804460

On Jul 5, 2014 12:59 PM, "Matt R" <matthew.r...@gmail.com> wrote:
Seems like your am command is a little different and yours unfortunately doesn't have any details on what the <intent> can include. Not sure how to help without the same am command.

Matt

Matt R

unread,
Jul 5, 2014, 1:12:44 PM7/5/14
to tas...@googlegroups.com
So are you using the autolaunch plugin or something else? Might want to put the link in case some else finds this in the future.

Matt

Rajat

unread,
Jul 5, 2014, 1:18:39 PM7/5/14
to tas...@googlegroups.com
Having not reached much headway with Tasker (which I'm sure has much to do with my not being an expert), I was suggested an app that did what I was trying to accomplish with the task.

The command I was after was a single but essential step in a longer task, so the other app doesn't just replace this step but the whole task itself that I was building in Tasker. You'll find the details in the XDA link I posted, and the app I now use is App Quarantine.


On Sat, Jul 5, 2014 at 10:42 PM, Matt R <matthew.r...@gmail.com> wrote:
So are you using the autolaunch plugin or something else? Might want to put the link in case some else finds this in the future.

Matt

Reply all
Reply to author
Forward
0 new messages