As mentioned in a comment, it should be the same as other Android devices.
You can try this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Card card = new Card(this);
card.setText("wifi " + MainActivity.isWiFiConnected(this) + " charger " + MainActivity.isChargerConnected(this));
setContentView(card.toView());
Log.v("TEST", "wifi " + MainActivity.isWiFiConnected(this));
Log.v("TEST", "charger " + MainActivity.isChargerConnected(this));
if(MainActivity.isWiFiConnected(this) && MainActivity.isChargerConnected(this)) {
// do whatever...
}
}
public static boolean isWiFiConnected(Context context) {
ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo.State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING)
return true;
return false;
}
public static boolean isChargerConnected(Context context) {
Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
}
Add
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
in the manifest.
Also, to check that Glass really connects to the internet, please see How to check if Google Glass is connected to internet using GDK.