Help with invoking built in Android functions

I am using APDE and it is great.

I want to invoke some of the built in functions on the Android device like

  • Taking ascreenshot
  • Turning on/off the wifi
  • etc.

Are there specific lines of code to call these specific functions?

To take a screenshot you can use processing’s functions. See here.
Almost everything can be done on Android but you have to do it programmatically.
Try the following code and please comment on the Android mode/version that you are using.
You will need the permissions ACCESS_WIFI_STATE and CHANGE_WIFI_STATE

import android.net.wifi.WifiManager;
import android.app.Activity;
import android.content.Context;

Activity act;
Context cnt;
boolean toggle;
WifiManager wifi;

void setup() {
  background(0, 0, 100); 
  fill(255);
  size(400, 400);
  textAlign(CENTER);
  textSize(25);
  text("Click to toggle Wifi On/Off", width/2, height/2);
  act = this.getActivity();
  cnt = act.getApplicationContext();
  wifi = (WifiManager) cnt.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
}

void draw() {
}

void mousePressed() {
  if (toggle) {
    wifi.setWifiEnabled(true);
    toggle = false;
  } else {
    wifi.setWifiEnabled(false);
    toggle = true;
  }
}

Thanks @noel I will check this now

Hi @noel I tried it on APDE and the app crashed. I have to try it on Processing [Android Mode] using Processing 1.5.1 in a sec

To give permissions on APDE you use the three dots right top, Sketch Properties / Sketch Permissions.
With Api I mean this.

Thanks I did that and it is enabled. APDE still crashes

@adaptinnovative === the app crashes: what error message? - What is the os of your phone?