galets
galets

Reputation: 18482

Android: How to output data to console script

I am trying to write an Android application, which is launched by a system script. Application is supposed to prompt for a text and output it to stdout, so that script could consume it. EDIT: To clarify something here: Script is launched by encfs --extpass option.

I know how android application can write to a console: System.console().printf("text");

I know how to launch activity from the script: am start -n com.pkg.App/.MyActivity

I have no idea how to actually make an application launched that way to actually output anything to the console that launched it. Application seems to go do its stuff, and nothing gets returned to console.

Maybe I am approaching the whole issue wrong and there is an easier way to prompt for a text from script?

Upvotes: 0

Views: 523

Answers (2)

Jeffrey Blattman
Jeffrey Blattman

Reputation: 22637

why not write an android app that hosts the entire sequence? android can use Runtime class to launch scripts or native command line applications. it can pass them arguments and capture the output and pass it on to other scripts, etc.

  1. launch your app, and gather the user input
  2. launch the system script, and pass it the argument gathered in step 1

if that doesn't work, for example, because you don't have control of when encfs needs to be invoked, another idea would be to launch the android app from the system script as you suggested, and have it write the output to a file when it's done. the system script would need to monitor for the existence of the file, because otherwise it would not know when the input is ready. leave System.console() out of it.

Upvotes: 1

Turbo J
Turbo J

Reputation: 7691

You can get access to the console via System.console() in API level >= 9. The NDK should also allow to write to the console.

Upvotes: 0

Related Questions