Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping a C command line executable in a standard Android application

Tags:

c

android

native

I have a C command line executable that I have successfully compiled for Android. I can copy the executable and launch it with Android Terminal Emulator on my Android ICS phone by doing the following:

  1. execute "export TERMINFO=/etc/terminfo"
  2. execute "mount -o remount rw /sdcard"
  3. launch the executable from the sdcard

Step one is necessary because the command line application makes use of the ncurses library and if i do not set TERMINFO then I get an error when I try launch the application. If I leave off the second step then I get an "Access denied" when I try launch the command line application from the sdcard. So, provided I manually do these steps I can launch the command line executable.

Now what I am wanting to do is to wrap this command line executable inside a standard Android application. The source for Android Terminal Emulator is open source and so I can use that to open an EmulatorView inside my Android application. My question though is how do I go about including the native executable inside the apk, deploying it to the device in a location where my application will have rights to execute it in the EmulatorView. I am a bit concerned about whether I will be able to get over the rights issue so that the native command line executable can be launched.

I do know about the Android NDK, but would prefer not to have to re-write a working command line application so that it can be included as a library. I am specifically looking at keeping the C executable source as it is and executing it from the wrapper application. Does anyone know whether this is possible and if so how I would go about doing it?

like image 219
BruceHill Avatar asked Jan 18 '26 17:01

BruceHill


1 Answers

If you copied the native file under your data folder where you should have appropriate permission, and then use Runtime.exec to execute your file.

You can create a bin folder (or any name) and copy your file under

Process exeProcess = 
         Runtime.getRuntime().exec("/data/data/YOUR_PACKAGE/bin/EXECUTABLE_FILE");

You can use the object exeProcess to read the data from your executable file.

like image 80
iTech Avatar answered Jan 20 '26 08:01

iTech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!