【问题标题】:Why I can't call using the Uri class?为什么我不能使用 Uri 类调用?
【发布时间】:2014-07-17 12:41:29
【问题描述】:

我正在使用以下代码从我的 android 代码中拨打电话。但它似乎不起作用。所有这些代码所做的只是在呼叫应用程序中显示电话号码,但它不呼叫。

Uri call=Uri.parse("tel:9008765750");//that's an example phone number
Intent ii= new Intent(Intent.ACTION_VIEW,call);
startActivity(ii);

【问题讨论】:

  • 而不是 Intent.ACTION_VIEW 使用 Intent.ACTION_CALL 并确保您在清单中声明权限]

标签: android android-intent uri phone-call


【解决方案1】:

改变

Intent ii= new Intent(Intent.ACTION_VIEW,call);

Intent ii= new Intent(Intent.ACTION_CALL,call);

并添加权限<uses-permission android:name="android.permission.CALL_PHONE" />

Intent.ACTION_VIEW 用于Display the data to the user.

因此,当您将tel:Intent.ACTION_VIEW 一起使用时,它只会显示数字。

Intent.ACTION_CALL 用于Perform a call to someone specified by the data.

【讨论】:

    【解决方案2】:

    试试这个

    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number"));
    startActivity(intent);
    

    清单中的权限:

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

    【讨论】:

    • 谢谢你,伙计,这就是我需要打电话的全部内容。
    【解决方案3】:

    你有在 manifest.xml 中声明 &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt; 吗?

    【讨论】:

    • 谢谢你,这就是我所需要的。连同 Intent.ACTION_CALL 。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多