本文整理汇总了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();
}
}
示例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();
}
}
示例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");
}
}
}
}
}
示例4: getSignalLevel
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static int getSignalLevel() {
WifiInfo wifiInfo = sWifiManager.getConnectionInfo();
return WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 5);
}
示例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);
}