2

I am trying to launch an android applications from native code.

In adb shell we can launch applications using "am" command.

Link:

How to run (not only install) an android application using .apk file?

Is there any way to invoke this "am" command through C code?

I tried the following line but exec is returning -1:

  ret = execl("/system/bin/am", "start", "-a", "android.intent.action.MAIN",
 "-n", "com.android.settings/.Settings", (char *)NULL);

Is this right or not?

5
  • 2
    Tried where? In Android? In PC? Commented Mar 2, 2012 at 8:34
  • in android only.. i put it in a working c code in android.... exec is failing Commented Mar 2, 2012 at 12:34
  • Does /system/bin/am start -a android.intent.action.MAIN -n com.android.settings/.Settings works launched from terminal? Commented Mar 2, 2012 at 13:40
  • ya its working in adb shell.. it will launch the settings menu Commented Mar 2, 2012 at 14:33
  • do we need run exec in vfork or something... ??? Commented Mar 2, 2012 at 15:35

2 Answers 2

1

I got the answer... I 'exec'ed the shell itself and gave it the command... It worked

ret = execl("/system/bin/sh", "sh", "-c", "am start -a android.intent.action.MAIN -n   com.android.browser/.BrowserActivity", (char *)NULL);

Thanks to m0skit0, Padma Kumar, Yuri ...

Sign up to request clarification or add additional context in comments.

1 Comment

It's not entirely clear why using a shell would make a difference here. However note that calling an exec family function without first calling fork() replaces the calling program - which, if that was an android app will look like a crash.
0

you should use system() family method ,first it will fork child process and invoke shell then return,so it will not block android main thread

2 Comments

This should maybe have been a comment, not an answer. With a bit more rep, you will be able to post comments.
system will block whatever thread it is called from. So don't call this from your main thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.