[Android] the mobile guard receives the call broadcast and displays the number home

Use the broadcast receiver to receive the call intention and display the number home

Create a new broadcastreceiver whose class outcallreceiver inherits the system

Override onreceive() method

Call the getresultdata () method to get the string phone number and query the database to get the home location

Define the < receiver > node and < intent Filter > node in the manifest file, and set the < action > node name, Android: name = "Android. Intent. Action. New"_ OUTGOING_ CALL”

Permission required, android.permission.process_ OUTGOING_ CALLS

Code registration broadcast

At this time, the broadcast receiver will be called as soon as it makes a call, and the user experience is not good. We use the code to register the broadcast receiver and control the broadcast by opening the part of monitoring phone calls in the setting center

Call the registerreceiver () method in the service to register the broadcast. Parameters: broadcastreceiver object and intentfilter object

Get the intentfilter object and call the addaction() method of the intentfilter object. Parameter: android.intent.action.new_ OUTGOING_ CALL

Unregister the broadcast in the service and call unregisterreceiver() method. Parameter: broadcastreceiver object

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>