Broadcast recipient
In reality: Radio to publish news, broadcast the message out, using the radio, you can listen to the radio, learned this message
Android: During the operation of the system, there will be many events, then some events, such as: Power changes, send and receive text messages, call, screen unlock, boot, the system will send a broadcast, as long as the application received this broadcast, the system has been aware of the corresponding event, so that the corresponding code execution. Use the broadcast receiver to listen to the broadcast
Create a broadcast recipient
Defining Java class inheritance Broadcastreceiver
Define the receiver node in the manifest file, define the Name property, and specify the full class name of the broadcast receiver Java class
In the Intent-filter node, specify the action child node, and the action value must match the action in the broadcast to be accepted, for example, if you want to accept a call to broadcast,
Then the value of the action must be specified as
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
Because the action contained in the call broadcast is "Android.intent.action.NEW_OUTGOING_CALL", so when we define the broadcast receiver,
Action must match to receive this broadcast
Even if the broadcast receiver's process has been closed, when the action in the broadcast by the system matches the action of the broadcast recipient, the system initiates the process where the broadcast receiver is located and sends the broadcast to the broadcast recipient.
SMS Firewall
When the system sends the text message broadcast, how to put the text message content to broadcast, we only then how to take out
If the text message is too long, then the send will be split into multiple text messages sent, then the text message broadcast will contain more than one text message
After 4.0, the broadcast receiver's process will not take effect if it has never been started.
After 4.0, if the system automatically shuts down the process where the broadcast recipient is located, when the action on the broadcast matches the action of the broadcast recipient, the system initiates the process where the broadcast receiver is located, but if the user manually shuts down the process, the process goes into a frozen state and is never started again. Until the next time the user starts the process manually.
Broadcast classified unordered broadcast
- All broadcast receivers that match the action on the broadcast can receive this broadcast, and are not sequential, and are considered to receive both
Orderly broadcast
- All broadcast receivers that match the action on the broadcast can receive the broadcast, but in sequence, sorted by the priority of the broadcast recipient
Service
Process priority
Foreground process: a process that has an activity that is interacting with the user (the Onresume method is called)
Visible process: Has an activity with visible but no focus (the OnPause method is called)
Service process: Has a service initiated through the StartService method
Background process: a process that has an invisible activity (the OnStop method is called)
Empty process: No process with any active app components
Status of Phone recorder phone
Call to detect the status of the phone, using the broadcast mechanism.
Idle state (phone hangs up)
TelephonyManager.CALL_STATE_IDLE
Ringing status
TelephonyManager.CALL_STATE_RINGING
Off-hook status (in call)
TelephonyManager.CALL_STATE_OFFHOOK
Recorder
Recording, is to use the service.
- The encoding and format of the audio file is not one by one corresponding
This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )
Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4912483.html
[Android App Development] 05. Broadcasting and Services