如何从 Android 应用中的意图获取 phone 数字

How to get a phone number from an intent in an Android app

我制作了一个设置为拨号器的应用程序。我不确定如何从我的应用程序外部获取某人点击的人的号码(例如 link 在浏览器中打开拨号器的号码)并选择我的应用程序作为拨号器。

我使用的意图过滤器:

        <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>

我曾经使用 getIntent 方法来获取意图本身,但我不确定何时应该调用 getData 以及何时调用 getExtras 因为它不是我创建的意图我自己以及在这种特定情况下不确定如何从意图中获取数字。

使用 getData() 提取形式为 tel:XXXXX 的 URI,这是您的 phone 号码。

Input: If nothing, an empty dialer is started; else getData() is URI of a phone number to be dialed or a tel: URI of an explicit phone number.

http://developer.android.com/reference/android/content/Intent.html#ACTION_DIAL

您可以尝试使用记录在案的函数 getNumberFromIntent(更多信息 here

希望对您有所帮助

 <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:linksClickable="true"/>

这个方法真的有效