Use an Intent action to
- start a dialer activity (ACTION)
- specify the number to dial using the tel: schema as the data component (DATA)
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:1234567"));
startActivity(intent);
Replacing the Native Dialer
Intercepting Intents that are currently serviced by the native dialer
Initiating, and optionally managing, outgoing calls.
<intent-filter> tags on your new Activity should listen for
Intent.ACTION_CALL_BUTTON
- This action is broadcast when the device’s hardware call button is pressed
- this Intent is used by applications which want to launch the dialer to make a phone call
- The view action is used by applications wanting to view a piece of data
android:name=".MyDialerActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" />
</intent-filter>
</activity>
Accessing Phone and Network Properties and Status
Access to the telephony APIs is managed by the Telephony Manager, accessible using the getSystemService method
String srvcName = Context.TELEPHONY_SERVICE;
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(srvcName);
Reading Phone Device Details
Monitoring Changes in Phone State Using the Phone State Listener
To monitor and manage phone state
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Monitoring Incoming Phone Calls
PhoneStateListener callStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
// TODO React to incoming call.
}
};
telephonyManager.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
state parameter represents the current call state
- TelephonyManager.CALL_STATE_IDLE
- When the phone is neither ringing nor in a call
- TelephonyManager.CALL_STATE_RINGING
- When the phone is ringing
- TelephonyManager.CALL_STATE_OFFHOOK
- When the phone is currently in a call
Telephony Manager will broadcast an ACTION_PHONE_STATE_CHANGED Intent when phone state changes as a result of
Intent also includes up to two extras:
intent.getStringExtra(TelephonyManager.EXTRA_STATE)
intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)
Can listen for incoming phone calls at any time, even if the application is not running.
It needs,
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
- incoming call
- accepted call
- terminated call
Intent also includes up to two extras:
intent.getStringExtra(TelephonyManager.EXTRA_STATE)
intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)
Can listen for incoming phone calls at any time, even if the application is not running.
It needs,
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
No comments:
Post a Comment