import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.util.Log;
public class WiFiUitl {
/**
* 获取蓝牙是否打开
* @return
*/
public static boolean getBluetoothState(){
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if(adapter == null)
return false;
int state = adapter.getState();
if(state == BluetoothAdapter.STATE_ON)
return true;
return false;
}
/**
* 获取wifi强度0-4
* @return
*/
public static int getWifiStrength(Context context){
WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
// WifiInfo wifiInfo = wifiManager.getConnectionInfo();
WifiInfo info = wifiManager.getConnectionInfo();
if (info.getBSSID() != null) {
// 链接信号强度
int strength = WifiManager.calculateSignalLevel(info.getRssi(), 4);
Log.i("WiFiUitl", "strength: "+strength);
return strength;
}
return 0;
}
/*public static int getVolume(Context context){
//音量控制,初始化定义
AudioManager mAudioManager = (AudioManager)context.getSystemService(context.AUDIO_SERVICE);
int max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM );
int current = mAudioManager.getStreamVolume(AudioManager.STREAM_SYSTEM );
return current;
} */
}