Android incoming call monitoring and outgoing call monitoring implementation code
I think writing an article must be useful. We must have our own ideas. The monitoring of incoming and outgoing calls will be carried out according to the following three questions
1. What's the use of monitoring incoming and outgoing calls?
2. How to monitor? Do you monitor incoming calls and outgoing calls in the same way?
3. In actual combat, what needs special attention?
What can I do by listening to incoming calls and going to electricity
1. Be able to make a mark on the phone heard by the supervisor and tell the user that the phone is fraud, promotion and advertising
2. It can automatically hang up for those special calls to avoid disturbing users
@H_ 502_ 16 @ monitoring method for incoming and outgoing calls (different method)
1. Incoming call listener
Incoming call monitoring uses the phonestatelistener class. The method of use is to register the phonestatelistener object (generally inheriting the phonestatelistener class to complete some encapsulation) into the system telephone management service (telephonymanager)
Then listen for incoming calls through the callback method oncallstatechanged (int state, string incomingnumber) of phonestatelistener (for detailed implementation, please refer to the extended reading section given later)
@H_ 502_ 16 @ register to listen
The oncallstatechanged method of phonestatelistener listens for incoming call status
Three state source code interpretation
2. Power off monitoring (through broadcasting)
In actual combat, what needs special attention
1. How to get dual card and dual standby mobile phones
For dual card mobile phones, each card corresponds to a service and a phonestatelistener. Each service needs to register its own phonestatelistener. The name of the service will change a little, and the manufacturer may modify it
2. Hang up
Hang up uses the interface provided by the system service to hang up, but hanging up is a method that does not guarantee success, so there are many ways to hang up at the same time, which are provided below
3. You need permission to hang up
The above is the Android incoming call monitoring and outgoing call monitoring introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!