Analysis of information obtained by connecting android to wif

Source: Internet
Author: User
Tags bssid

Android parameters are roughly divided into two parts: system service parameters and platform system information.

System Service parameters: the Android system service not only refers to service components, but also includes the service functions provided by the Android system. Android provides interfaces-managers for these system service parameters. Different components are managed by different managers, including Wi-Fi management, connection management, telephone management, and power management, vibration management, Volume management, Input Method management, window management, etc. Through these system service interfaces, we can easily obtain system information. Here I will take some managers that may be related to the Huawei project for careful research.

Wi-Fi Management (important ):

Wifimanager wifi_service = (wifimanager) getsystemservice (wifi_service );

// Obtain the attributes of the Wi-Fi configuration interface

List wificonfig = wifi_service.getconfigurednetworks ();

Wificonfig contains four attributes:

Bssid: BSS is a special ad-hoc LAN (a wireless network application model that supports point-to-point access ).

A wireless network consists of at least one AP connected to a wired network and several Wireless

Workstation composition. This configuration is called a basic service device. A group of computers have the same settings

The BSS name can be a group, and the BSS name is called bssid. Usually, hand

In WLAN, bssid is actually the MAC address of the wireless route.

Networkid: network ID.

Presharedkey: Security Authentication Mode for wireless networks.

SSID: The SSID (Service Set identif) is used to identify the wireless LAN. The SSID varies with the wireless network.

The network cannot communicate with each other.

// Obtain wi-fi connection information

Wifiinfo = wifi_service.getconnectioninfo ();

Wifiinfo. getbssid (): Obtain bssis (as described above ).

Wifiinfo. getssid (): Get the SSID (as described above ).

Wifiinfo. getipaddress (): Obtain the IP address.

Wifiinfo. getmacaddress (): Obtain the MAC address.

Wifiinfo. getnetworkid (): Obtain the network ID.

Wifiinfo. getlinkspeed (): gets the connection speed, allowing you to know this information.

Wifiinfo. getreceipt (): Obtain the receipt of the signal strength indication. You can directly

Compare with the Wi-Fi signal thresholds provided by Huawei to provide users

Or adjust the geographic location to achieve the best connection effect.



// Obtain DHCP Information

Dhcpinfo = wifi_service.getdhcpinfo ();

IPaddress: Obtain the IP address.

Gateway: Obtain the gateway.

Netmask: Obtain the subnet mask.

Dns1: Obtain DNS.

Dns2: Obtain the backup DNS.

Serveraddress: Get the server address.


// Obtain scan information

List scanresult = wifi_service.getscanresults ();

Bssid: Obtain bssid (as described above ).

SSID: Get the network name (as described above ).

Level: Obtain the signal level.

Frequency: Obtain frequency.

Capabilites: Security description of the Access Point.

// Obtain the Wi-Fi network status

Int wifistate = wifi_service.getwifistate ();

Wifi_state_disabling: constant 0, indicating being disabled.

Wifi_state_disabled: constant 1, indicating unavailability.

Wifi_state_enabling: constant 2, indicating starting.

Wifi_state_enabled: constant 3, indicating readiness.

Wifi_state_unknown: constant 4, indicating the unknown state.

Note: During network connection, these statuses will be displayed on notification, straight

You can obtain the status here to complete Wi-Fi in Huawei notification.

Status display requirement.



Connection Management:

Connectivitymanager connectionmanager = (connectivitymanager)

Getsystemservice (connectivity_service );

// Obtain the network status information in the following three methods:

Networkinfo = connectionmanager. getactivenetworkinfo ();

Networkinfo wifiinfo =

Connectionmanager. getnetworkinfo (connectivitymanager. type_wifi );

Networkinfo mobileinfo =

Connectionmanager. getnetworkinfo (connectivitymanager. type_mobile );

Getdetailedstate (): Get the detailed status.

Getextrainfo (): Get additional information.

Getreason (): Get the reason for connection failure.

GetType (): gets the network type (generally mobile or Wi-Fi ).

Gettypename (): Get the network type name (generally set to "WiFi" or "mobile ").

Isavailable (): determines whether the Network is available.

Isconnected (): determines whether a connection is established.

Isconnectedorconnecting (): determines whether a connection is established or is in progress.

Isfailover (): determines whether the connection fails.

Isroaming (): determines whether to roam.



// Use the network status listener

Write a service class in the program to inherit broadcasrreceiver:

Public class NetMonitor extends broadcastreceiver {

Public void onreceive (context, intent ){

}

}

Declare the rervice in androidmanifest. xml:

<Service android: Name = "NetMonitor" Android: lable = "NetMonitor">

<Intent-filter>

<Action Android: Name = "android.net. Conn. connectivity_change"/>

</Intent-filter>

</Service>

When the network status changes, you can use the rervice to listen to the changes and make corresponding

.



Power Management:

Powermanager power = (powermanager) getsystemservice (power_service );

Partial_wake_lock: screen off and keyboard off.

Screen_dim_wake_lock: the screen side is dark and the keyboard is disabled.

Screen_bright_wake_lock: the screen is lit and the keyboard is disabled.

Full_wake_lock: the screen is lit and the keyboard is lit.

Acquire_causes_wakeup: force the screen or keyboard to be clicked immediately when the device is awakened by the wake-up lock

Bright (for example, notifications as important information ).

On_after_release: When the wake-up lock is released, the user's Activity component is reset.

Displays long events on the screen.

// Wake up the device based on the specified level by the "acquire" method of the wake-up lock.

You can use the "release" method to release it.

Powermanager. wakelock locker = powermanager. newwakelock (powermanager.

Acquire_causes_wakeup | powermanager. screen_bright_wake_lock,

"Powerservicedemo ");

Locker. Acquire ();

Locker. Release ();

Vibration management:

Vibrator vibrator = (vibrator) getsystemservice (vibrator_service );

Through the "vibrate" method of the vibrator, you can set the duration of the vibration and start the vibration.

The "cancel" method of the program to cancel the vibration, or when the user program exits, all user-initiated vibrations will be stopped.

.



Platform System Information: The Android platform encapsulates process management, file system, environment variables, system time, platform information, battery management, and other core components of the system, this allows developers to obtain more information about core systems.



Android. OS. Process

// Obtain the method of the current process

Android. OS. process. getelapsedcputime (): Get the consumed time.

Android. OS. process. mypid (): gets the ID of the process.

Android. OS. process. mytid (): gets the ID of the calling process.

Android. OS. process. myuid (): Obtain the user ID of the process.

Android. OS. process. supportsprocesses: determines whether the process supports multiple processes.



// Obtain/set the thread priority

Getthreadpriority (INT tid): gets the priority of the thread with the specified ID.

Setthreadpriority (INT priority): sets the priority of the current thread.

Setthreadpriority (INT tid, int priority): sets the priority of the thread with the specified ID.



// Manage processes

Killprocess (int pid): Kill the specified process.

Sendsignal (int pid, int singal): sends a signal to a specified process.



Android. OS. Environment

// Obtain system environment variables

Getdatadirectory (): obtains the environment variables of the data folder in the current system.

Getdownloadcachedirectory (): obtains the environment variables for downloading cached files from the current system.

Getexternalstoragedirectory (): Get the environment variable of the external storage file in the current system.

Getrootdirectory (): Get the environment variable of the root file in the current system.

Related Article

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.