android extern functions

Monkey Targets Forums/Android/android extern functions

hub(Posted 2015) [#1]
Is there a way to send a line command to android with monkey ?
I'm trying tho shutdown the system. when the user quit my appli.
(rooted).
Thanks !


Xaron(Posted 2015) [#2]
Not with plain monkey. You have to write your own java code and wrap it to use it with Monkey.


hub(Posted 2015) [#3]


uhm... next should be difficult to include this somewhere ;-)


hub(Posted 2015) [#4]
Not with plain monkey. You have to write your own java code and wrap it to use it with Monkey.

is it difficult to do this ?


hub(Posted 2015) [#5]
Why not just use 'Execute' ? from brl.process.

Someone have an exemple with this on android target ?

Thanks !


therevills(Posted 2015) [#6]
You will need to extern your command in MonkeyX.

Something like this:

Android code: hub.java
class hub {
  static void reboot() {
    try {
      Process proc = Runtime.getRuntime().exec(new String[]{ "su", "-c", "reboot -p" });
      proc.waitFor();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}


Monkey code
Import "hub.java"

Extern
  Function Reboot:Void() = "hub.reboot"



hub(Posted 2015) [#7]
Many thanks Therevills.

Do you think that is possible to use this method to provide an simple extern DialogBox ? as Blitzmax 'Notify' ? i'm searching how to set this from here :

http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog

So i could display an error message inside a Dialogbox just with an Ok button. (Today i use a log file !).


hub(Posted 2015) [#8]
.


hub(Posted 2015) [#9]
Perhaps just a toast ?


I'm not a java coder, someone could help me to undestand what's wrong ? Is it possible with monkey ?


hub(Posted 2015) [#10]
.


therevills(Posted 2015) [#11]
Have a look in the Diddy source, there is already the AlertDialog extern in there (under showAlertDialog):

https://code.google.com/p/diddy/source/browse/src/diddy/native/diddy.android.java


hub(Posted 2015) [#12]
i'm trying to test with your java showAlertDialog. Compilation is now ok. But finaly my appli stop and i can display the message. So perhaps my android system have a bug with this !

- If you use plain monkey code like this : Error "Your message here". Do you have the 'Your message here' displayed on android device ? (On my system the appli stop and not display the "Your message here" but "Unfortunately (your app) has stopped (translated from french).

Could you compile for android an apk file just with ShowAlertDialog in action and send me to hubert.bayre(at)wanadoo.fr so i can test that it's not a problem with my android system.

many thanks Therevills.


therevills(Posted 2015) [#13]
Hmmmm.... looks like the internals of Monkey has changed (again!).

Can you try this APK:
http://www.therevillsgames.com/code/monkey/MonkeyGame-debug.apk

Here is the code behind it:
hub.monkey


hub.java



hub(Posted 2015) [#14]
Perfect ! Many thanks for all this help. All work fine now.

I've just a problem to draw an image to mouse pointer position now. The os pointer move on the screen, but i must click to have my own image pointer set at MouseX(), MouseY(). i need to read more the doc about this. (i use a keyboard with a touchpad connected via wireless usb).