下面列出了android.content.Intent#ACTION_DIAL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void callPhone(JSONArray args) throws JSONException {
String number = args.getString(0);
number = number.replaceAll("#", "%23");
if (!number.startsWith("tel:")) {
number = String.format("tel:%s", number);
}
try {
boolean bypassAppChooser = Boolean.parseBoolean(args.getString(1));
boolean enableTelephony = isTelephonyEnabled();
Intent intent = new Intent(enableTelephony? (bypassAppChooser? Intent.ACTION_DIAL : Intent.ACTION_CALL) : Intent.ACTION_VIEW);
intent.setData(Uri.parse(number));
if ((enableTelephony==false) && bypassAppChooser) {
intent.setPackage(getDialerPackage(intent));
}
cordova.getActivity().startActivity(intent);
callbackContext.success();
} catch (Exception e) {
callbackContext.error("CouldNotCallPhoneNumber");
}
}
private void listing6_2() {
// Listing 6-2: Implicitly starting an Activity
if (somethingWeird && itDontLookGood) {
// Create the implicit Intent to use to start a new Activity.
Intent intent =
new Intent(Intent.ACTION_DIAL, Uri.parse("tel:555-2368"));
// Check if an Activity exists to perform this action.
PackageManager pm = getPackageManager();
ComponentName cn = intent.resolveActivity(pm);
if (cn == null) {
// There is no Activity available to perform the action
// Log an error and modify app behavior accordingly,
// typically by disabling the UI element that would allow
// users to attempt this action.
Log.e(TAG, "Intent could not resolve to an Activity.");
}
else
startActivity(intent);
}
}
private static void startInsecureCallInternal(@NonNull Activity activity, @NonNull Recipient recipient) {
try {
Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + recipient.requireSmsAddress()));
activity.startActivity(dialIntent);
} catch (ActivityNotFoundException anfe) {
Log.w(TAG, anfe);
Dialogs.showAlertDialog(activity,
activity.getString(R.string.ConversationActivity_calls_not_supported),
activity.getString(R.string.ConversationActivity_this_device_does_not_appear_to_support_dial_actions));
}
}
@OnClick(R.id.tvPhoneNumber)
void openRestaurantPhoneNo(View view) {
if (business != null) {
Intent i = new Intent(Intent.ACTION_DIAL);
i.setData(Uri.fromParts("tel", business.getPhone(), null));
startActivity(i);
}
}
@Override
public void makeACall(Customer customer) {
if(customer.getBillingAddress() != null){
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:" + customer.getBillingAddress().getPhone()));
startActivity(callIntent);
}
}
/**
* 获取跳至拨号界面意图
* @param phoneNumber 电话号码
* @param isNewTask 是否开启新的任务栈
* @return 跳至拨号界面意图
*/
public static Intent getDialIntent(final String phoneNumber, final boolean isNewTask) {
try {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
return getIntent(intent, isNewTask);
} catch (Exception e) {
LogPrintUtils.eTag(TAG, e, "getDialIntent");
}
return null;
}
/**
* Call telephone number.
* Non direct call, opens up the dialer and pre-sets the telephone number. User needs to press manually.
* Direct call requires M permission granted, also add permissions to manifest:
* <uses-permission android:name="android.permission.CALL_PHONE" />
*
* @param telNo The telephone number to call
* @param directCall Direct call number if possible
*/
@SuppressWarnings("SimplifiableConditionalExpression")
public void callTelephoneNumber(final String telNo, final boolean... directCall) {
Activity activity = greedyGetActivity();
if (activity == null) {
throw new RuntimeException("Error: ShareUtil::callTelephoneNumber needs to be contstructed with activity context");
}
boolean ldirectCall = (directCall != null && directCall.length > 0) ? directCall[0] : true;
if (android.os.Build.VERSION.SDK_INT >= 23 && ldirectCall && activity != null) {
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.CALL_PHONE}, 4001);
ldirectCall = false;
} else {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + telNo));
activity.startActivity(callIntent);
} catch (Exception ignored) {
ldirectCall = false;
}
}
}
// Show dialer up with telephone number pre-inserted
if (!ldirectCall) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", telNo, null));
activity.startActivity(intent);
}
}
public static void openDialActivity(Context context, String phoneNumber)
{
try
{
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
context.startActivity(intent);
}
catch (ActivityNotFoundException activityException)
{
Log.d("PhoneUtil", "openDialActivity: ", activityException);
}
}
/**
* 跳转到系统拨号界面
* @param context
* @param toDialTelNo
*/
public static void jumpToSystemDialUi(Context context, String toDialTelNo) {
Intent startIntent = new Intent(Intent.ACTION_DIAL);
if (!Util.isEmpty(toDialTelNo)) {
startIntent.setData(Uri.parse("tel:" + toDialTelNo));
}
jumpToActivity(context, startIntent, 0, false);
}
/**
* Phone call
* @param phonenum
*/
public static void callPhone(Context context, String phonenum) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phonenum));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
public void onReject (DialogInterface dialog, @NonNull Activity activity) {
Intent callSupportIntent = new Intent(Intent.ACTION_DIAL, GlobalSetting.SUPPORT_NUMBER_URI);
activity.startActivity(callSupportIntent);
}
@Action(Intent.ACTION_DIAL)
@Uri("tel:{phone}")
void startTel(@UriReplace("phone") String phone);
/**
* Creates Intent for calling a phone.
*/
public static Intent createCallPhoneIntent(String phoneNumber) {
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
return callIntent;
}
public static void openDail(Context context) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
public static void openDial(Context context, String number) {
Uri uri = Uri.parse("tel:" + number);
Intent it = new Intent(Intent.ACTION_DIAL, uri);
context.startActivity(it);
}
private void call() {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + getString(R.string.cooptel_phone_number)));
startActivity(intent);
}
@SuppressWarnings("UnusedParameters")
public void callSafeRide(View view) {
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:12129928267"));
startActivity(callIntent);
}
/** 进入拨号界面 */
public static void dial(@NonNull Context context, @NonNull String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
/**
* 拨打电话
*
* @param context
* @param number
*/
public static void openDial(Context context, String number) {
Uri uri = Uri.parse("tel:" + number);
Intent it = new Intent(Intent.ACTION_DIAL, uri);
context.startActivity(it);
}
/**
* 携带电话号码跳转到拨号界面
*
* @param context
* @param phoneNumber
*/
public static void actionDial(Context context, String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
context.startActivity(intent);
}