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);
}
}
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);
}
}
相关文章推荐
- android developer tiny share-20160829
- android developer tiny share-20160627
- android developer tiny share-20160628
- android developer tiny share-20160712
- android developer tiny share-20160719
- android developer tiny share-20160715
- android developer tiny share-20160711
- android developer tiny share-20160714
- android developer tiny share-20160707
- android developer tiny share-20160719
- android developer tiny share-20160628
- android developer tiny share-20160704
- android developer tiny share-20160701
- android developer tiny share-20160714
- android developer tiny share-20160706
- android developer tiny share-20160627
- android developer tiny share-20160701
- android developer tiny share-20160705
- android developer tiny share-20160718
- android developer tiny share-20160715