exec命令Android原生code命令、exec、code、Android

2023-09-06 19:32:36 作者:倾一夕思念

我试图发起从本地code的Andr​​oid应用程序。

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

在亚洲开发银行的外壳,我们可以通过启动应用程序是命令。

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

链接:

How使用的.apk文件运行(不只是安装)Android应用程序?

有没有办法来调用这个我,通过C code命令?

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

我尝试了以下线,但EXEC将返回-1:

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?

推荐答案

我得到了答案...... 我exec'ed壳本身并赋予它命令它的工作

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);

由于m0skit0,帕德玛·库马尔,尤里......

Thanks to m0skit0, Padma Kumar, Yuri ...