Android get system WiFi status etc.

Source: Internet
Author: User

Wifi

  Get WiFi status

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

if (Wifimanager! = null) {

int wifistate = Wifimanager.getwifistate ();

}

Attached: WiFi status has the following: (in parentheses for the corresponding int value)

1. wifimanager.wifi_state_disabled (1)

2. Wifimanager. Wifi_state_enabled (3)

3. Wifimanager. Wifi_state_disabling (0)

4 Wifimanager. Wifi_state_enabling (2)

Set WiFi status

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

if (Wifimanager = = null) {

Return

}

int wifiapstate = Wifimanager.getwifiapstate (); Get WiFi AP Status

if (boolean && wifiapstate = = Wifimanager.wifi_ap_state_enabling | | wifiapstate = = Wifimanager.wifi_ap_state_ ENABLED) {

Wifimanager.setwifiapenabled (Null,false);

}

Wifimanager.setwifienabled (boolean value);

The Boolean value should be the same in both places

Bluetooth

Bluetooth needs to be added later

Gps

Get GPS status

Contentresolver Resolver = context. Contextresolver ();

Boolean on = Settings.Secure.isLocationProviderEnabled (resolver, locationmanager.gps_provider);

True to turn on state

To set the GPS status:

Settings. Secure.setlocationproviderenabled (Resolver,locationmanager.gps_provider,boolean value);

True to turn on state

Sync (synchronous)

gets the current system synchronization status

Contentresolver Resolver = context. Contextresolver ();

Boolean on = resolver.getmastersyncautomatically ();

Connectivitymanager Connmanager = (connectivitymanager) context.getsystemservice (Context.connectivity_service);

Setting up synchronization

Contentresolver.setmastersyncautomatically (boolean value);

Airplanemode (flight mode)

  Get system current flight mode status

Contentresolver Resolver = context. Contextresolver ();

Boolean on = Settings.System.getInt (Context.getcontextresolver (), settings.system.airplane_mode_on,0) = = 1? True:false;

  Set Airplane mode:

Settings.System.putInt (Context.getcontentresolver (), Settings.system.airplane_mode_on,boolean value? 1:0);

Intent Intent = new Intent (intent.action_airplane_mode_changed);

Intent.putextra ("state", Boolean value);

Context.sendbroadcast (Intent);

The two Boolean values should be the same;

Automatically rotate the screen

  Get system Current Auto-spin screen settings

Contentresolver Resolver = context. Contextresolver ();

Boolean on = Settings.System.getInt (Context.getcontresolver (), Settings.System.ACCELEROMETER_ROTATION) ==1? True:false;

  Set up automatic spin screen

Contentresolver Resolver = context. Contextresolver ();

Uri uri = Settings.System.getUriFor ("accelerometer_rotation");

Settings.System.putInt (resolver, "Accelerometer_rotation", Boolean? 1:0);

Resolver.notifychange (Uri,null);

Mute mode

Get silent mode

public int Getmutemode (context context) {

Audiomanager Audiomanager = (audiomanager) context.getsystmservice (Context.audio_service);

if (Audiomanager.getringermode = = audiomanager.ringer_mode_silent) {//Mute

return 0;

}else if (Audiomanager.getringermode = = audiomanager.ringer_mode_vibrate) {//Vibration

return 1;

} elsse {

RETRN 2;

}

}

Set Mute mode

public void Setmute (context context) {

Audiomanager Audiomanager = (audiomanager) context.getsystmservice (Context.audio_service);

Switch (Getmutemode (context) {

Case 0:

Audiomanager.stringermode (audiomanager.ringer_mode_vibrate); Vibration mode

Break

Case 1:

Audiomanager.stringermode (Audiomanager.ringer_mode_normal); Normal mode

Break

Case 2:

Audiomanager.stringermode (audiomanager.ringer_mode_silent); Mute mode

Break

Default

Audiomanager.stringermode (Audiomanager.ringer_mode_normal); Normal mode

}

}

Lock screen

PowerManager pm = (powermanager) context.getsystemservice (context. Power_service);

Pm.gotosleep (Systemclock.uptimemillis ());

Android get system WiFi status etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.