We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have developed a few android applications that I want to start from a master android app. I thought it was going to be pretty simple by using "open" function, however, I have spent a few hours dealing with it.
I compiled in Java mode and works fine, but in android mode It finds the file, however, at the time to execute it drops the error below. Could anybody please give me a clue ? I will appreciate it very much !
My testing code is:
import java.io.IOException;
void setup() {
size(200, 200);
}
void draw() {
// draw() must be present for mousePressed() to work
}
void mousePressed() {
println("Opening Process");
File set = new File("/sdcard/usbStorage/alarmSetting.txt"); //It finds the file but does not execute ???
if (set.exists())
{ println("Start to execute");
open ("/sdcard/usbStorage/alarmSetting.txt");
}
else {println("File set does not exist");}
}
The error is:
Opening Process
Start to execute
java.io.IOException: Error running exec(). Command: [/sdcard/usbStorage/alarmSetting.txt] Working Directory: null Environment: null
at java.lang.ProcessManager.exec(ProcessManager.java:224)
at java.lang.Runtime.exec(Runtime.java:189)
at java.lang.Runtime.exec(Runtime.java:136)
at processing.core.PApplet.exec(Unknown Source)
at processing.core.PApplet.open(Unknown Source)
at processing.core.PApplet.open(Unknown Source)
at processing.test.openapp.openApp.mousePressed(openApp.java:36)
at processing.core.PApplet.mousePressed(Unknown Source)
at processing.core.PApplet.handleMouseEvent(Unknown Source)
at processing.core.PApplet.dequeueEvents(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(PGraphicsAndroid2D.java:169)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:1019)
Caused by: java.io.IOException: Permission denied
at java.lang.ProcessManager.exec(Native Method)
at java.lang.ProcessManager.exec(ProcessManager.java:222)
... 13 more
FATAL EXCEPTION: Animation Thread
java.lang.RuntimeException: Could not open /sdcard/usbStorage/alarmSetting.txt
at processing.core.PApplet.exec(Unknown Source)
at processing.core.PApplet.open(Unknown Source)
at processing.core.PApplet.open(Unknown Source)
at processing.test.openapp.openApp.mousePressed(openApp.java:36)
at processing.core.PApplet.mousePressed(Unknown Source)
at processing.core.PApplet.handleMouseEvent(Unknown Source)
at processing.core.PApplet.dequeueEvents(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(PGraphicsAndroid2D.java:169)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:1019)
Answers
Processing's
open()
method clearly doesn't work on Android, and this is likely because it has not been re-written to work in an Android environment. Android doesn't have executable files in the same way that Desktop operating systems do; to start an application (a native AndroidActivity
), you must create anIntent
and include the package and the class of theActivity
that you want to start (you can also specify a more genericIntent
that lets the user select from a list of possible candidates). Depending on the way that you intend to implement this, your solution will vary. First, I recommend that you read Android's Intents Tutorial (keep in mind that this is written for native Android and you will need to pick and choose which information you can successfully implement).Thanks a lot for your guidance. I´ll try as you per your recommendation.