如何让拨号器打开并显示电话号码? [英] How do I get the dialer to open with phone number displayed?

查看:67
本文介绍了如何让拨号器打开并显示电话号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不需要拨打电话号码,我只需要打开已显示电话号码的拨号器即可.我应该使用什么 Intent 来实现这一点?

I don't need to call the phone number, I just need the dialer to open with the phone number already displayed. What Intent should I use to achieve this?

推荐答案

两种方式实现.

1) 需要通过代码启动拨号器,无需用户交互.

您需要Action_Dial

使用下面的代码将打开指定号码的拨号器

use below code it will open Dialer with number specified

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent); 

需要'tel:'前缀,否则会抛出以下异常:java.lang.IllegalStateException:无法执行活动的方法.

The 'tel:' prefix is required, otherwhise the following exception will be thrown: java.lang.IllegalStateException: Could not execute method of the activity.

Action_Dial 不需要任何许可.

如果您想直接发起呼叫而无需用户交互,您可以使用操作Intent.ACTION_CALL.在这种情况下,您必须在 AndroidManifest.xml 中添加以下权限:

If you want to initiate the call directly without user's interaction , You can use action Intent.ACTION_CALL. In this case, you must add the following permission in your AndroidManifest.xml:

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

2) 需要用户点击 Phone_Number 字符串并开始通话.

android:autoLink="phone" 

您需要使用具有以下属性的 TextView.

You need to use TextView with below property.

android:autoLink=手机"android:linksClickable="true"一个 textView 属性

您不需要使用意图或通过这种方式获得许可.

You don't need to use intent or to get permission via this way.

这篇关于如何让拨号器打开并显示电话号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆