问题
What are the intents that are broadcasted in the following events,
- Wifi state change
- Bluetooth state change
- Ringer mode change
回答1:
For Wifi state changes:
WifiManager.WIFI_STATE_CHANGED_ACTION ("android.net.wifi.WIFI_STATE_CHANGED")
Broadcast intent action indicating that Wi-Fi has been enabled, disabled, enabling, disabling, or unknown. One extra provides this state as an int. Another extra provides the previous state, if available.
WifiManager.NETWORK_STATE_CHANGED_ACTION ("android.net.wifi.STATE_CHANGE")
Broadcast intent action indicating that the state of Wi-Fi connectivity has changed. One extra provides the new state in the form of a NetworkInfo object. If the new state is CONNECTED, a second extra may provide the BSSID of the access point, as a String.
WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION ("android.net.wifi.supplicant.CONNECTION_CHANGE")
Broadcast intent action indicating that a connection to the supplicant has been established (and it is now possible to perform Wi-Fi operations) or the connection to the supplicant has been lost. One extra provides the connection state as a boolean, where true means CONNECTED.
Also take a look at ConnectivityManager.CONNECTIVITY_ACTION ("android.net.conn.CONNECTIVITY_CHANGE")
A change in network connectivity has occurred. A connection has either been established or lost. The NetworkInfo for the affected network is sent as an extra; it should be consulted to see what kind of connectivity event occurred.
If this is a connection that was the result of failing over from a disconnected network, then the FAILOVER_CONNECTION boolean extra is set to true.
For a loss of connectivity, if the connectivity manager is attempting to connect (or has already connected) to another network, the NetworkInfo for the new network is also passed as an extra. This lets any receivers of the broadcast know that they should not necessarily tell the user that no data traffic will be possible. Instead, the reciever should expect another broadcast soon, indicating either that the failover attempt succeeded (and so there is still overall data connectivity), or that the failover attempt failed, meaning that all connectivity has been lost.
For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY is set to true if there are no connected networks at all.
For Bluetooth state changes:
BluetoothAdapter.ACTION_STATE_CHANGED ("android.bluetooth.adapter.action.STATE_CHANGED")
Broadcast Action: The state of the local Bluetooth adapter has been changed. For example, Bluetooth has been turned on or off.
and for Ringer mode changes:
AudioManager.RINGER_MODE_CHANGED_ACTION ("android.media.RINGER_MODE_CHANGED")
Sticky broadcast intent action indicating that the ringer mode has changed. Includes the new ringer mode.
Not a ringer mode change, but this can be good to have also AudioManager.VIBRATE_SETTING_CHANGED_ACTION ("android.media.VIBRATE_SETTING_CHANGED")
Broadcast intent action indicating that the vibrate setting has changed. Includes the vibrate type and its new setting.
(Ops, got no rep so only 2 links... :( )
来源:https://stackoverflow.com/questions/4297647/broadcast-intents-for-bluetooth-wifi-and-ringer-mode