Created
April 5, 2015 08:26
-
-
Save yankchina/8cd317eaa357ca6524a6 to your computer and use it in GitHub Desktop.
判定 Android 是否连上 WiFi,并且获取当前 IP 地址
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sl4a | |
import socket, struct | |
def check_wifi_info(): | |
droid = sl4a.Android() | |
wifiState = droid.checkWifiState() | |
if wifiState: | |
ipdec = droid.wifiGetConnectionInfo().result['ip_address'] | |
ipstr = socket.inet_ntoa(struct.pack('L',ipdec)) | |
droid.makeToast(ipstr) | |
return wifiState | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment