Four components of Android development to realize telephone interception and telephone recording
1、 Problem description
Use the bordercasterceiver and service components to realize the following functions:
1. When the mobile phone is in the incoming call state, start the monitoring service to monitor and record the incoming call.
2. Set the phone blacklist. When the incoming call is a blacklist phone, hang up directly.
When a call is made or the phone status changes, the system will issue an orderly broadcast. Therefore, we can use the bordercasterreceiver to accept the broadcast. Because the bordercasterreceiver has a short execution time and cannot perform time-consuming tasks or use sub threads, we should start a service to listen to the phone and process it
2、 Add Aidl file
Android does not have an API to end a call publicly. To end a call, you must use Aidl to communicate with the telephone management service and call the API in the service to end the call. In this way, the Android source code files neighoringcellinfo.aidl and itelephony.aidl need to be added to the project, as shown in the figure:
Android studio will automatically compile the corresponding class file
3、 Writing a telreceiver component
Registered broadcast:
4、 Writing the listenphoneservice component
Service XML configuration
5、 Finally, don't forget to set some permissions
<!-- Add permission to access mobile phone status -- > < uses permission Android: name = "Android. Permission. Read_phone_state" / > <-- Call permission -- > < uses permission Android: name = "Android. Permission. Call_phone" / > <-- Monitor the power of mobile phone -- > < uses permission Android: name = "Android. Permission. Process_outgoing_calls" / > <-- Create and delete file permissions in sdcard -- > < uses permission Android: name = "Android. Permission. Mount_unmount_filesystems" / > <-- Write data permission to sdcard -- > < uses permission Android: name = "Android. Permission. Write_external_storage" / >
Well, the above is all described in this article. I hope it will help you learn the four basic components of Android. Thank you.