您的位置:首页 > 移动开发 > Android开发

android developer tiny share-20160829

2016-09-01 11:02 106 查看
今天讲通过intent实现拨打电话,同时会讲ACTION_DIAL和ACTION_CALL的区别。

Phone

Initiate a phone call


To open the phone app and dial a phone number, use the ACTION_DIAL action and specify a phone number using the URI scheme defined below. When the phone app opens, it displays the phone number but the user must press the Call button to begin the phone call.

To place a phone call directly, use the ACTION_CALL action and specify a phone number using the URI scheme defined below. When the phone app opens, it begins the phone call; the user does not need to press the Call button.

The ACTION_CALL action requires that you add the CALL_PHONE permission to your manifest file:

<uses-permission android:name="android.permission.CALL_PHONE" />

Action


    ACTION_DIAL - Opens the dialer or phone app.

    ACTION_CALL - Places a phone call (requires the CALL_PHONE permission)
Data URI Scheme

    tel:<phone-number>

    voicemail:<phone-number>
MIME Type

    None

Valid telephone numbers are those defined in the IETF RFC 3966. Valid examples include the following:

tel:2125551212
tel:(212) 555 1212

The Phone's dialer is good at normalizing schemes, such as telephone numbers. So the scheme described isn't strictly required in the Uri.parse() method. However, if you have not tried a scheme or are unsure whether it can be handled, use the Uri.fromParts()
method instead.

Example intent:

public void dialPhoneNumber(String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息