I am trying to write a java plugin for the Android Monkeyrunner to check the WiFi state. I would like to use the Android API WiFiManager to get the current WiFi state and return it back.
The error message in Eclipse is: The method getWifiState() is undefined for the type MonkeyWifi
How can I change the code to be able to get the current WiFi status?
This is the code I have so far:
package com.my.android.wifi;
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
import com.android.monkeyrunner.MonkeyDevice;
import com.google.common.base.Predicate;
import android.net.wifi.WifiManager;
public class MonkeyWifi implements Predicate<PythonInterpreter> {
public class NewActivity extends Activity {
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
}
public int WifiStatus(){
int state;
state = wifiManager.getWifiState();
return state;
}
@Override
public boolean apply(PythonInterpreter arg0) {
return false;
}
}
You can use AndroidViewClient instead (version 8.26.0 or higher), then you would be able to access basic wifi information.
A basic script to check wifi state would be along these lines
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from com.dtmilano.android.viewclient import ViewClient
from com.dtmilano.android.adb.adbclient import WIFI_SERVICE, WifiManager
device, serialno = ViewClient.connectToDeviceOrExit()
wifiManager = device.getSystemService(WIFI_SERVICE)
print "wifi state:", wifiManager.getWifiState()