Report to the Manager
To get at much of the phone API, you use the . That class lets you do things like:
• Determine if the phone is in use via , with return values of (phone not in use), (call requested but still being connected), and (call in progress)
• Find out the SIM ID (IMSI) via
• Find out the phone type (e.g., GSM) via or find out the data connection type (e.g., GPRS, EDGE) via
You Make the Call!
You can also initiate a call from your application, such as from a phone number you obtained through your own Web service. To do this, simply craft an with a of the form (where is the phone number to dial) and use that with . This will not actually dial the phone; rather, it activates the dialer activity, from which the user can then press a button to place the call.
For example, let’s look at the sample application. Here’s the crude‑but‑effective layout:
We have a labeled field for typing in a phone number, plus a button for dialing said number.
The Java code simply launches the dialer using the phone number from the field:
Package
Import
Import
Import
Import
Import
Import
Import
Public class extends
Public onCreate
Super onCreate
SetContentView
Final findViewById
FindViewById
SetOnClickListener new OnClickListener
Public onClick
GetText toString
StartActivity new Intent
Parse
The activity’s own UI is not that impressive as shown in Figure 35‑1.
Figure 35‑1. The DialerDemo sample application, as initially launched
However, the dialer you get from clicking the dial button is better, showing you the number you are about to dial in Figure 35‑2.
Figure 35‑2. The Android Dialer activity, as launched from DialerDemo
Дата добавления: 2015-05-16; просмотров: 855;