1

I got following question:

I would like to call a Android native binary (in my case PING) from Java source. So I know this is possible by creating a new process and listening for its OutputStream - but I wonder if it´s not possible to use JNI for this.

I thought about creating a new binary called JNIPING which offers a method that can be invoced from java. This method could exec the PING binary and return it´s output to the JNI caller...

So for me this sounds quite possible - but I´m really poor in C, so I´d like to ask you if there is anybody who can tell me how to do this -- or if it´s not possible, so I don´t need to spend lot of time in that...

Thanks so much for your response!

PS: I tried something like that in my JNIPING:

#include<stdio.h>
#include<stdlib.h>
int main() {
    char str[256], buf[256];
    printf("myshell-> ");
    scanf("%s", str);
    sprintf(buf, "ping www.google.de\n", str);
    system(buf);
    return 0;
}

So how can I get the output from the binary to send it back to java?

koch.trier
  • 604
  • 8
  • 21

1 Answers1

0

You can use the Process and Runtime class to do this, see this question.

Another possibility should be to use InetAddress.isReachable, see this question

However, both methods seem to fail in the ping case under Android.

Community
  • 1
  • 1
Matthieu Poullet
  • 417
  • 1
  • 9
  • 20