In this particular guide, you will find out about the droid Telephony and SMS API. You will discover ways to build a phone call out of your software and how to watch phone call occasions, as well as simple tips to send and receive Text Message.
1. Making A Call
To begin, let me show you a way to begin a call because of your software often by utilizing the cell dialer application or directly from your application to really make it more comfortable for their users.
Come up with a unique Android Os Facility Job
Light up Android work and produce a brand new plan with a clear action named MainActivity .
Lay Out the Display
For the moment, all of our format will only need an EditText field and a Dial option:
Modify the MainActivity Classroom
During the code prevent below, we’ve been producing an ACTION_DIAL motive to display the telephone dialer. The device amounts are parsed from our tel URI scheme: tel:XXXXXXXX . Keep in mind that you don’t need any consent in this to be hired:
Any time you work the application and then click the switch switch, you’ll be taken to the dialer software, and after that you’ll have to actually call the number. You can easily changes this stream to truly boost the risk for telephone call from within your very own app just by modifying the ACTION_DIAL intention to ACTION_CALL rather. This will call for the droid.permission.CALL_PHONE approval, nevertheless.
2. Monitoring Phone Call Events
In this part, we are going to find out how to supervise phone call functions when you look at the droid process. The device are in three claims:
- lazy (when it’s unused)
- ringing in the ears (when there is an incoming phone call)
- off-hook (whenever telephone call try responded)
Use the consent
We’d like the authorization READ_PHONE_STATE having the capacity to watch the device state. Include it with AndroidManifest.xml:
Make the PhoneStateListener Thing
We setup a thing associated with PhoneStateListener classroom, after which outrank its onCallStateChanged() way (in IntelliJ you can perform this with Control-O, and then select or locate the method to outrank). (more…)