Passing path arguments to an executable in android

asked 2014-05-02 00:38:03 -0600

user21011993 gravatar image

updated 2014-05-02 03:15:09 -0600

berak gravatar image

I have implemented a C++ OpenCV program that extracts characters from images. I want to integrate this program into an android app that takes picture and extracts the characters. For this I have tried cross-compiling C code into arm. I have been able to pass some string arguments and successfully print them inside the executable. Now I am trying to pass path references to a file and try to open the file inside the executable. Here is the code involved for the C file that is turned into an executable:

#include <stdio.h>
int main (int argc, char** argv )
{
char* filename_image;
char* filename_output;
FILE *fp;
if(argc >= 2 )
{
filename_image = argv[1];
filename_output = argv[2];
printf("This is testing...\n");

fp = fopen(filename_output,"r");

if( fp == NULL )
  {
printf("file cannot open...\n");
     perror("Error while opening the file.\n");
     return;
    // exit(EXIT_FAILURE);
  }
fprintf(fp, "This is testing...\n");
printf("testing done...\n");

fclose(fp);
return;
}

}

and From android I call:

Process process = new ProcessBuilder(executableFilePath,"/sdcard/Pictures/MyCameraApp"+"/param2.txt").start()

Note: /sdcard/Pictures/MyCameraApp/param1.txt and /sdcard/Pictures/MyCameraApp/param2.txt are the paths to files i have created on my device. The output in the LogCat window is: The message file cannot open... Error while opening the file

Any help will be greatly appreciated.

edit retag flag offensive close merge delete

Comments

Could it be that you have to enable writing permissions on external files, other than your executable first?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-02 02:47:46 -0600 )edit
1

apart from your first problem, you open fp for reading, then you try to write to it ?

berak gravatar imageberak ( 2014-05-02 02:56:47 -0600 )edit
1

The second is a typo. I tried it with "w".

user21011993 gravatar imageuser21011993 ( 2014-05-02 09:48:37 -0600 )edit

yea, thought so, too.

berak gravatar imageberak ( 2014-05-02 09:55:15 -0600 )edit