Using the built-in Phone Application is a handy way to access telephonic functions, but it is very limited. To really get under the skin of our mobile radio we need to make use of the android.telephony package which contains many useful classes. Here we will use the TelephonyManager and the PhoneStateListener classes to create a simple application that records the phone's state during incoming and outgoing calls while the application is running.
This application requires no external resources, so simply start up a new Android project in Eclipse and open the Manifest file.
To allow our application to use the phone device, include the following permission inside the
<activity>
node:<uses-permission android:name="READ_PHONE_STATE" />
Open the
res/layout/main.xml
file, remove theandroid:text
element, and provide this resource ID:android:id="@+id/text_view"
We will place all our Java code within the
onCreate()
method of our Java...