當前位置: 首頁>>代碼示例>>Java>>正文


Java WifiManager.calculateSignalLevel方法代碼示例

本文整理匯總了Java中android.net.wifi.WifiManager.calculateSignalLevel方法的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager.calculateSignalLevel方法的具體用法?Java WifiManager.calculateSignalLevel怎麽用?Java WifiManager.calculateSignalLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.wifi.WifiManager的用法示例。


在下文中一共展示了WifiManager.calculateSignalLevel方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onReceive

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    WifiManager wifiManager = (WifiManager) context
            .getSystemService(context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo.getBSSID() != null) {
        // wifi信號強度
        int signalLevel = WifiManager.calculateSignalLevel(
                wifiInfo.getRssi(), 4);
        if (signalLevel == 0) {
            imgNetWorkState.setImageDrawable(context.getResources()
                    .getDrawable(R.drawable.wifi_1));
        } else if (signalLevel == 1) {
            imgNetWorkState.setImageDrawable(context.getResources()
                    .getDrawable(R.drawable.wifi_2));

        } else if (signalLevel == 2) {
            imgNetWorkState.setImageDrawable(context.getResources()
                    .getDrawable(R.drawable.wifi_3));

        } else if (signalLevel == 3) {
            imgNetWorkState.setImageDrawable(context.getResources()
                    .getDrawable(R.drawable.networkstate_on));
        }
        if (d)
            Toast.makeText(context, "wifi level" + signalLevel,
                    Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:Evan-Galvin,項目名稱:FreeStreams-TVLauncher,代碼行數:30,代碼來源:GameTitleView.java

示例2: onReceive

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
	WifiManager wifiManager = (WifiManager) context
			.getSystemService(context.WIFI_SERVICE);
	WifiInfo wifiInfo = wifiManager.getConnectionInfo();
	if (wifiInfo.getBSSID() != null) {
		// wifi信號強度
		int signalLevel = WifiManager.calculateSignalLevel(
				wifiInfo.getRssi(), 4);
		if (signalLevel == 0) {
			imgNetWorkState.setImageDrawable(context.getResources()
					.getDrawable(R.drawable.wifi_1));

		} else if (signalLevel == 1) {
			imgNetWorkState.setImageDrawable(context.getResources()
					.getDrawable(R.drawable.wifi_2));

		} else if (signalLevel == 2) {
			imgNetWorkState.setImageDrawable(context.getResources()
					.getDrawable(R.drawable.wifi_3));

		} else if (signalLevel == 3) {
			imgNetWorkState.setImageDrawable(context.getResources()
					.getDrawable(R.drawable.networkstate_on));
		}
		if (d)
			Toast.makeText(context, "wifi level" + signalLevel,
					Toast.LENGTH_SHORT).show();
	}
}
 
開發者ID:Evan-Galvin,項目名稱:FreeStreams-TVLauncher,代碼行數:31,代碼來源:TitleView.java

示例3: onRequestPermissionsResult

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == 0x12345) {
        for (int grantResult : grantResults) {
            if (grantResult != PackageManager.PERMISSION_GRANTED) {
                return;
            }
        }
        WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        boolean wasEnabled = myWifiManager.isWifiEnabled();
        if (!wasEnabled)
            myWifiManager.setWifiEnabled(true);
        if (myWifiManager.isWifiEnabled()) {
            if (myWifiManager.startScan()) {
                // List available APs
                Log.d("pras", "this inside scan");
                List<ScanResult> scans = myWifiManager.getScanResults();
                Log.d("pras", "" + (scans == null));
                Log.d("pras", "" + scans.isEmpty());
                if (scans != null && !scans.isEmpty()) {
                    for (ScanResult scan : scans) {
                        int level = WifiManager.calculateSignalLevel(scan.level, 20);
                        //Other code
                        Log.d("wifi", level + "this");
                    }
                } else {
                    Log.d("pras", "this inside else");
                }
            }
        }

    }

}
 
開發者ID:PrasannaNatarajan,項目名稱:Interrobang,代碼行數:35,代碼來源:MainActivity.java

示例4: getSignalLevel

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static int getSignalLevel() {
    WifiInfo wifiInfo = sWifiManager.getConnectionInfo();
    return WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 5);
}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:5,代碼來源:NetworkUtils.java

示例5: getBars

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * Get the number of bars in the range 1 - 4.
 *
 * @return
 */
public int getBars() {
    return WifiManager.calculateSignalLevel(level, 5);
}
 
開發者ID:KennethEvans,項目名稱:Misc,代碼行數:9,代碼來源:WifiActivity.java


注:本文中的android.net.wifi.WifiManager.calculateSignalLevel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。