2

I was wanting to create a android application where I could quickly write basic java code and get it to output in a TextView. I originally got this idea up and running messing around in intellij and thought it would be a cool app so I started building it in android studio. What I was planning to do was create a 'dummy' java file, parse my code into the file, then execute the file. That way java would do all of the heavy lifting.

I am a student so I want this app as a way to practice writing sorting algorithms/recursive functions... basically the stuff they ask you to program in job interviews. I should also mention that this is research for my final school project.

Here is what I have already tried to do.

I have added permission in my manifest

< uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/ >

and this is how I am trying to create the file.

String FILENAME = "Interpreter.java";
String string = "hello world!";
try {
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
}catch(Exception e){

}

I do not know where the file is being created if at all...

Am i going in the right direction? does anyone know if this is even possible in android?

Thank you in advance!

  • a complete solution posted here: http://stackoverflow.com/questions/7887078/android-saving-file-to-external-storage – ymz Nov 27 '14 at 02:28
  • Your direction is in some way right, you're miles away though. `.java` needs to be compiled into bytecode before the virtual machine can understand it, with desktop java you could be using something like http://stackoverflow.com/questions/2158429/compiling-and-running-user-code-with-javacompiler-and-classloader - for android you can't do just that you'll have to provide special `dex` bytecode for the DalvikVM (or now ART, which I guess can convert dex to it's own thing on the fly?). For that you'd need either a compiler from java to dex directly or like the dx tool convert desktop .class files – zapl Nov 27 '14 at 02:34
  • http://stackoverflow.com/questions/2610995/dynamically-generating-dalvik-bytecode-into-a-running-dalvik-android-application has some related information and there is https://play.google.com/store/apps/details?id=com.aide.ui which can create actual android apps from within an app. So it's been done. – zapl Nov 27 '14 at 02:36

0 Answers0