本文整理匯總了Java中android.net.wifi.WifiManager類的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager類的具體用法?Java WifiManager怎麽用?Java WifiManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WifiManager類屬於android.net.wifi包,在下文中一共展示了WifiManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getWifiSSID
import android.net.wifi.WifiManager; //導入依賴的package包/類
/**
* Gets the SSID of the currently associated WiFi access point if there is one. Otherwise,
* returns empty string.
*/
@CalledByNative
public static String getWifiSSID(Context context) {
if (context == null) {
return "";
}
final Intent intent = context.registerReceiver(
null, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
if (intent != null) {
final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
if (wifiInfo != null) {
final String ssid = wifiInfo.getSSID();
if (ssid != null) {
return ssid;
}
}
}
return "";
}
示例2: getSSID
import android.net.wifi.WifiManager; //導入依賴的package包/類
public String getSSID() {
WifiManager wifiManager = (WifiManager) getSystemService("wifi");
if (wifiManager == null) {
return null;
}
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo == null) {
return null;
}
String ssid = connectionInfo.getSSID();
if (ssid == null) {
ssid = null;
}
return ssid;
}
示例3: GetWifiDBM
import android.net.wifi.WifiManager; //導入依賴的package包/類
public int GetWifiDBM() {
int dbm = 0;
WifiManager wifiManager = (WifiManager) _context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiManager == null) {
return -1;
}
if (wifiManager.isWifiEnabled()) {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
dbm = wifiInfo.getRssi();
}
}
return dbm;
}
示例4: handleButtonPress
import android.net.wifi.WifiManager; //導入依賴的package包/類
@Override
public void handleButtonPress(int index) {
if (index == 0) {
WifiParsedResult wifiResult = (WifiParsedResult) getResult();
WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
if (wifiManager == null) {
Log.w(TAG, "No WifiManager available from device");
return;
}
final Activity activity = getActivity();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(activity.getApplicationContext(), R.string.wifi_changing_network, Toast.LENGTH_SHORT).show();
}
});
new WifiConfigManager(wifiManager).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, wifiResult);
parent.restartPreviewAfterDelay(0L);
}
}
示例5: connectToKnownWifi
import android.net.wifi.WifiManager; //導入依賴的package包/類
public static void connectToKnownWifi(Context context, String ssid) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for (WifiConfiguration i : list) {
if (i.SSID != null && i.SSID.equals("\"" + ssid + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
}
}
}
示例6: onReceive
import android.net.wifi.WifiManager; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
WifiManager wifiMgr = (WifiManager) context.getApplicationContext()
.getSystemService(Service.WIFI_SERVICE);
if (wifiMgr.isWifiEnabled()) {
context.startService(new Intent(context, DeskDroidService.class));
} else {
context.stopService(new Intent(context, DeskDroidService.class));
}
}
示例7: getWifiListNearby
import android.net.wifi.WifiManager; //導入依賴的package包/類
public List<Map<String, String>> getWifiListNearby() {
List<Map<String, String>> arrayList = new ArrayList();
if (this.a == null) {
return arrayList;
}
WifiManager wifiManager = (WifiManager) this.a.getSystemService("wifi");
if (wifiManager == null) {
return arrayList;
}
List<ScanResult> scanResults = wifiManager.getScanResults();
if (scanResults == null) {
return arrayList;
}
for (ScanResult scanResult : scanResults) {
Map hashMap = new HashMap();
hashMap.put("wifiMac", scanResult.BSSID == null ? "" : scanResult.BSSID);
hashMap.put("ssid", scanResult.SSID);
hashMap.put("rssi", scanResult.level);
arrayList.add(hashMap);
}
return arrayList;
}
示例8: wifiConnection
import android.net.wifi.WifiManager; //導入依賴的package包/類
public static boolean wifiConnection(Context context, String wifiSSID, String password) {
WifiManager wifi = (WifiManager) context.getSystemService("wifi");
String strQuotationSSID = "\"" + wifiSSID + "\"";
WifiInfo wifiInfo = wifi.getConnectionInfo();
if (wifiInfo != null && (wifiSSID.equals(wifiInfo.getSSID()) || strQuotationSSID.equals(wifiInfo.getSSID()))) {
return true;
}
List<ScanResult> scanResults = wifi.getScanResults();
if (scanResults == null || scanResults.size() == 0) {
return false;
}
for (int nAllIndex = scanResults.size() - 1; nAllIndex >= 0; nAllIndex--) {
String strScanSSID = ((ScanResult) scanResults.get(nAllIndex)).SSID;
if (wifiSSID.equals(strScanSSID) || strQuotationSSID.equals(strScanSSID)) {
WifiConfiguration config = new WifiConfiguration();
config.SSID = strQuotationSSID;
config.preSharedKey = "\"" + password + "\"";
config.status = 2;
return wifi.enableNetwork(wifi.addNetwork(config), false);
}
}
return false;
}
示例9: getScanResultsByBSSID
import android.net.wifi.WifiManager; //導入依賴的package包/類
public static ScanResult getScanResultsByBSSID(Context context, String bssid) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
ScanResult scanResult = null;
boolean f = wifiManager.startScan();
if (!f) {
getScanResultsByBSSID(context, bssid);
}
List<ScanResult> list = wifiManager.getScanResults();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
scanResult = list.get(i);
if (scanResult.BSSID.equals(bssid)) {
break;
}
}
}
return scanResult;
}
示例10: onWifiEnabled
import android.net.wifi.WifiManager; //導入依賴的package包/類
@Override
public void onWifiEnabled()
{
wifiLog("WIFI ENABLED...");
unregisterReceiver(mContext, mWifiStateReceiver);
if (mWifiStateListener != null)
mWifiStateListener.isSuccess(true);
if (mScanResultsListener != null || mPassword != null)
{
wifiLog("START SCANNING....");
if (mWifiManager.startScan())
registerReceiver(mContext, mWifiScanReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
else
{
if (mScanResultsListener != null)
mScanResultsListener.onScanResults(new ArrayList<>());
if (mConnectionWpsListener != null)
mConnectionWpsListener.isSuccessful(false);
mWifiConnectionCallback.errorConnect();
wifiLog("COULDN'T SCAN ERROR");
}
}
}
示例11: LockManager
import android.net.wifi.WifiManager; //導入依賴的package包/類
public LockManager(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "RedPhone Full");
partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RedPhone Partial");
proximityLock = new ProximityLock(pm);
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RedPhone Wifi");
fullLock.setReferenceCounted(false);
partialLock.setReferenceCounted(false);
wifiLock.setReferenceCounted(false);
accelerometerListener = new AccelerometerListener(context, new AccelerometerListener.OrientationListener() {
@Override
public void orientationChanged(int newOrientation) {
orientation = newOrientation;
Log.d(TAG, "Orentation Update: " + newOrientation);
updateInCallLockState();
}
});
wifiLockEnforced = isWifiPowerActiveModeEnabled(context);
}
示例12: getMacAddressByWifiInfo
import android.net.wifi.WifiManager; //導入依賴的package包/類
/**
* <p>need permission {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p>
*/
@SuppressLint("HardwareIds")
private static String getMacAddressByWifiInfo(Context context) {
try {
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (wifi != null) {
WifiInfo info = wifi.getConnectionInfo();
if (info != null) return info.getMacAddress();
}
} catch (Exception e) {
e.printStackTrace();
}
return "02:00:00:00:00:00";
}
示例13: writeToEntropyPool
import android.net.wifi.WifiManager; //導入依賴的package包/類
@Override
protected void writeToEntropyPool(DataOutputStream out) throws IOException {
super.writeToEntropyPool(out);
out.writeInt(android.os.Process.myPid());
out.writeInt(android.os.Process.myTid());
out.writeInt(android.os.Process.myUid());
if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT);
if (Build.SERIAL != null) out.writeUTF(Build.SERIAL);
ContentResolver contentResolver = appContext.getContentResolver();
String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
if (id != null) out.writeUTF(id);
Parcel parcel = Parcel.obtain();
WifiManager wm =
(WifiManager) appContext.getSystemService(WIFI_SERVICE);
List<WifiConfiguration> configs = wm.getConfiguredNetworks();
if (configs != null) {
for (WifiConfiguration config : configs)
parcel.writeParcelable(config, 0);
}
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
if (bt != null) {
for (BluetoothDevice device : bt.getBondedDevices())
parcel.writeParcelable(device, 0);
}
out.write(parcel.marshall());
parcel.recycle();
}
示例14: checkWifiConnection
import android.net.wifi.WifiManager; //導入依賴的package包/類
private void checkWifiConnection(){
try{
if(isWifiConnected()){
Toast.makeText(getApplicationContext(), "Wifi is connected", Toast.LENGTH_SHORT).show();
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
final String activeWifiName = wifiInfo.getSSID().replace("\"","");
btnActiveWifi.setText(activeWifiName);
//debug
btnActiveWifi.setText(btnActiveWifi.getText()+"\n("+AutoLoginService.getState(getBaseContext())+")");
}
else{
btnActiveWifi.setText("Wifi Not Connected !!");
//debug
btnActiveWifi.setText(btnActiveWifi.getText()+"\n("+AutoLoginService.getState(getBaseContext())+")");
}}
catch (Exception ex){
txtView.setText(ex.getMessage());
//Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG);
}
}
示例15: onReceive
import android.net.wifi.WifiManager; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent)
{
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
String name = wifiInfo.getSSID();
for(ScanResult result: wifiMgr.getScanResults()){
WifiApListProvider.this.output(new WifiAp(result, name.equals(result.SSID)));
}
WifiApListProvider.this.finish();
}