android獲取系統wifi狀態等

2021-07-29 19:21:44 字數 2889 閱讀 1252

**:

wifi

獲取wifi狀態

wifimanager wifimanager = (wifimanager)context.getsystemservice(context.wifi_service);

if(wifimanager != null)

附:wifi狀態有以下幾種:(括號內為所對應的的int值)

1. wifimanager.wifi_state_disabled (1)

2. wifimanager..wifi_state_enabled (3)

3. wifimanager..wifi_state_disabling (0)

4 wifimanager..wifi_state_enabling  (2)

設定wifi狀態

wifimanager wifimanager = (wifimanager) context.getsystemservice(context.wifi_service);

if(wifimanager == null)

int wifiapstate = wifimanager.getwifiapstate();  //獲取wifi ap狀態

if((boolean值 && wifiapstate == wifimanager.wifi_ap_state_enabling || wifiapstate == wifimanager.wifi_ap_state_enabled)

wifimanager.setwifienabled(boolean值);

倆處boolean值應相同

bluetooth

藍芽有待後續補充

gps

獲取gps狀態

contentresolver resolver = context.contextresolver();

boolean on = settings.secure.islocationproviderenabled(resolver, locationmanager.gps_provider);

true為開啟狀態

設定gps狀態:

settings..secure.setlocationproviderenabled(resolver,locationmanager.gps_provider,boolean值);

true為開啟狀態

sync(同步)

獲取當前系統同步狀態

contentresolver resolver = context.contextresolver();

boolean on = resolver.getmastersyncautomatically();

connectivitymanager connmanager = (connectivitymanager) context.getsystemservice(context.connectivity_service);

設定同步

contentresolver.setmastersyncautomatically(boolean值);

airplanemode(飛行模式)

獲取系統當前飛行模式狀態

contentresolver resolver = context.contextresolver();

boolean on = settings.system.getint(context.getcontextresolver(),settings.system.airplane_mode_on,0) == 1 ? true : false;

設定飛行模式:

settings.system.putint(context.getcontentresolver(),settings.system.airplane_mode_on,boolean值 ? 1 : 0);

intent intent = new intent(intent.action_airplane_mode_changed);

intent.putextra("state",boolean值);

context.sendbroadcast(intent);

倆個boolean值應該一致;

自動轉屏

獲取系統當前自動旋屏設定

contentresolver resolver = context.contextresolver();

boolean on = settings.system.getint(context.getcontresolver(),settings.system.accelerometer_rotation) ==1 ? true : false;

設定自動旋屏

contentresolver resolver = context.contextresolver();

uri uri = settings.system.geturifor("accelerometer_rotation");

settings.system.putint(resolver,"accelerometer_rotation",boolean值 ? 1 :0);

resolver.notifychange(uri,null);

靜音模式

獲取靜音模式

public int getmutemode(context context)else if(audiomanager.getringermode == audiomanager.ringer_mode_vibrate) elsse

}設定靜音模式

public void setmute(context context)}鎖屏

powermanager pm = (powermanager)context.getsystemservice(context.power_service);

pm.gotosleep(systemclock.uptimemillis());

Android如何獲取Wifi名稱(SSID)

其實很簡單,可以使用wifimanager和wifiinfo來獲取當前wifi連線資訊 wifimanager wifimanager wifimanager getsystemservice wifi service wifiinfo wifiinfo wifimanager.getconnect...

Android如何獲取Wifi名稱即SSID

可以使用wifimanager和wifiinfo來獲取當前wifi連線資訊 wifimanager wifimanager wifimanager getsystemservice wifi service wifiinfo wifiinfo wifimanager.getconnectioninf...

Android工具類 獲取wifi模組MAC位址

public class macutil else if build.version.sdk int build.version codes.m build.version.sdk int build.version codes.n else if build.version.sdk int bui...