編輯:Android開發實例
本文實例講述了Android編程實現獲取當前連接wifi名字的方法。分享給大家供大家參考,具體如下:
WifiManager wifiMgr = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE);
int wifiState = wifiMgr.getWifiState();
WifiInfo info = wifiMgr.getConnectionInfo();
String wifiId = info != null ? info.getSSID() : null;
public static InetAddress getWifiIp() {
Context myContext = Globals.getContext();
if (myContext == null) {
throw new NullPointerException("Global context is null");
}
WifiManager wifiMgr = (WifiManager) myContext.getSystemService(Context.WIFI_SERVICE);
if (isWifiEnabled()) {
int ipAsInt = wifiMgr.getConnectionInfo().getIpAddress();
if (ipAsInt == 0) {
return null;
} else {
return Util.intToInet(ipAsInt);
}
} else {
return null;
}
}
// 取得wifi的ip地址
InetAddress address = FTPServerService.getWifiIp();
address.getHostAddress();
public static boolean isWifiEnabled() {
Context myContext = Globals.getContext();
if (myContext == null) {
throw new NullPointerException("Global context is null");
}
WifiManager wifiMgr = (WifiManager) myContext.getSystemService(Context.WIFI_SERVICE);
if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
ConnectivityManager connManager = (ConnectivityManager) myContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiInfo = connManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return wifiInfo.isConnected();
} else {
return false;
}
}
// 打開wifi設置的頁面
Intent intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
startActivity(intent);
希望本文所述對大家Android程序設計有所幫助。
Android RSS客戶端開發實例之三:在UI中顯示RSS列表
前面兩部分分別講了RSS概述和解析XML文件,本節講解怎樣在列表中顯示RSS內
Android MediaPlayer(多媒體播放)
Android提供了許多方法來控制播放的音頻/視頻文件和流。其中該方法是通過一類稱為MediaPlayer。Android是提供MediaPlayer類訪問內置的媒體播放
Android 編程下字庫的使用及注意事項
在安卓操作系統下對於 TextView 字體的支持非常有限,默認情況下 TextView 的 typeface 屬性支持 Sans,serif,monospace
Android登錄實例
登錄應用程序的屏幕,詢問憑據登錄到一些特定的應用。可能需要登錄到Facebook,微博等本章介紹了,如何創建一個登錄界面,以及如何管理安全問題和錯誤嘗試。首先,必須定義兩