0

I have the C source code for a program that generates images based on parameters the user gives in a shell. It takes parameters and then generates a bitmap image and saves it to the local disk. I want to modify it so that I can call the image generation function from Java, and somehow get access to the bmp file that is generated.

How do I get access to the generated image file? Can the C program save to some sort of android local disk? Can I get the image file into a Java object in memory?

Aymon Fournier
  • 4,323
  • 12
  • 42
  • 59

2 Answers2

0

You can run a program using this class on Android. http://developer.android.com/reference/java/lang/Runtime.html

You want to use one of the version of Runtime.exec. You'll need to compile your C program using the NDK and include it in your APK.

Eric Urban
  • 3,671
  • 1
  • 18
  • 23
  • 1
    Yes, but unless there is a licensing issue it is strongly preferred to compile the program as a library and call into it from a JNI wrapper, rather than execute a new process from an executable that must be explicitly deployed. – Chris Stratton Feb 25 '14 at 03:28
  • @ChrisStratton The question is titled "Can I call a C program...". Not "Can you give me a strongly preferred way of solving my problem?" – Eric Urban Mar 03 '14 at 16:37
  • Please take note of the wording of the question "I want to **modify** it so that I can **call** the image generation function from Java" (emphasis added) and tell me if you think that sounds more like starting an executable, or calling a function? Also, even if starting an executable were the intent, we are not restricted from pointing out better approaches, especially when posting a *comment* rather than an *answer*. – Chris Stratton Mar 03 '14 at 17:02
  • Additionally, your proposal here is insufficient, as you cannot simply "include it in your APK" - that works for a jni library which Android will automatically copy out in runnable form, but not for an executable which your program will have to copy from the apk to the actual filesystem itself. – Chris Stratton Mar 03 '14 at 17:04
0

Android provides app private files hive, see http://developer.android.com/guide/topics/data/data-storage.html#filesInternal. You get its full path in Java as Context.getFilesDir(), and you can find this path from native code.

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307