本文整理匯總了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);
}