google gdk - How can I know Glass is connected to wifi and battery is charging -
i'm developing needs upload whole load of images, think it's better when glass both connected wifi , battery charger. also, if in idle mode it'll best.
where can put image upload code requirement fulfilled?
as mentioned in comment, should same 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)) { // 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 manifest.
also, check glass connects internet, please see how check if google glass connected internet using gdk.
Comments
Post a Comment