创建调用Runtime.getRuntime()在Android的新工艺 [英] Create new process with Runtime.getRuntime() in Android

查看:151
本文介绍了创建调用Runtime.getRuntime()在Android的新工艺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索的一个问题网页后,我有我找到<一href=\"http://stackoverflow.com/questions/21279270/android-can-native-$c$c-get-broadcast-intent-from-android-system\">that的回答。

After searching the web about a problem I have I found that answer.

在短暂的,我需要从一个Android应用程序生成一个新的进程,并运行一个简单的C程序。
我已经创建了简单的C程序,比如下一个:

in brief, I need to spawn a new process from an Android application, and run a simple C program. I've created simple C program, like the next one:

int main()
{
 printf("This is the message before sleep() function\n");
 while(1){
    Sleep(1000); 
 }
 printf("This is the message after 1 second");
 return 0;
}

Iv'e遵循的C程序用Cygwin的下一个命令(GCC myProgram.c -o myProgram)。

Iv'e complied the C program with Cygwin with the next command (gcc myProgram.c -o myProgram).

Iv'e把该文件中的文件夹入资产和我在节目的开头到内部设备存储器的文件夹复制它数据/数据​​/的packageName /文件/ MyProgram

Iv'e put that file in the assest folder and I copied it at the begining of the program to the internal device memory to the folder "data/data/packageName/files/myProgram".

现在我要执行的程序,当我会检查,亚行的shell - > PS我想看到两个过程具有相同的名称,但我不能找到它。

Now I want to execute the program, and when I will check, adb shell -> ps I want to see two process with the same name, but I can't find it.

我试图像这样运行程序:

I am trying to run the program like this:

调用Runtime.getRuntime()。EXEC(行chmod 755
  数据/数据​​/的packageName /文件/ MyProgram);

Runtime.getRuntime().exec("chmod 755 data/data/packageName/files/myProgram");

这是行不通的,我无法找到两个过程,我不知道这是正确的方式。

This is not working, I can't find two process, and I don't know if this is the right way.

我在做什么错了?

感谢。

推荐答案

您需要部署的二进制文件系统中,这是不标记为不可执行的位置(这就是为什么 / SD卡/ 等常见的地方没有帮助)。你需要选择该平台(armeabi,或86,或MIPS)相匹配的可执行文件的版本。您应该确保您部署的文件具有可执行权限。

You need to deploy the binary to the file system, to a location which is not marked as non-executable (that's why /sdcard/ and other common places don't help). You need to choose the version of your executable that matches the platform (armeabi, or x86, or mips). You should make sure that the file you deployed has the eXecutable permission.

要确保这一切的最简单方法是你的二进制文件的手臂构建复制到 $ {} project_root /libs/armeabi/lib_myProgram_.so ,并同其它相关的ABI。现在APK生成器将包二进制(S),并且安装程序将解压它们(具有可执行权限) /数据/数据​​/ your.package.name .with.dots /lib/lib_myProgram_.so

The easiest way to ensure all this is to copy the arm build of your binary to ${project_root}/libs/armeabi/lib_myProgram_.so, and same for other relevant ABIs. Now the APK builder will pack the binary(s), and the installer will unpack them (with eXecutable permissions) to /data/data/your.package.name.with.dots/lib/lib_myProgram_.so.

所有该做的,只需从Java调用(以下行可以从活动或服务被调用,即有机会获得背景

All this done, you simply call from Java (the following line can be called from Activity or Service, which have access to context):

Runtime.getRuntime().exec(getContext().getApplicationInfo().nativeLibraryDir + "lib_myProgram_.so");

这篇关于创建调用Runtime.getRuntime()在Android的新工艺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆