gpt4 book ai didi

android - 如何在 Android 中使用 Intent 调用电话?

转载 作者:IT老高 更新时间:2023-10-28 12:50:15 25 4
gpt4 key购买 nike

我正在使用以下代码在 Android 中调用电话,但它给了我安全异常,请帮助。

 posted_by = "111-333-222-4";

String uri = "tel:" + posted_by.trim() ;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);

权限

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

异常(exception)

11-25 14:47:01.661: ERROR/AndroidRuntime(302): Uncaught handler: thread main exiting due to uncaught exception
11-25 14:47:01.681: ERROR/AndroidRuntime(302): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:111-333-222-4 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{43d32508 302:com.Finditnear/10026} (pid=302, uid=10026) requires android.permission.CALL_PHONE
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.os.Parcel.readException(Parcel.java:1218)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.os.Parcel.readException(Parcel.java:1206)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1214)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.app.Activity.startActivityForResult(Activity.java:2749)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.app.Activity.startActivity(Activity.java:2855)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at com.Finditnear.PostDetail$2$1$1$1.onClick(PostDetail.java:604)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:884)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.widget.ListView.performItemClick(ListView.java:3285)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)

最佳答案

您可以使用 Intent.ACTION_DIAL 代替 Intent.ACTION_CALL。这将显示已输入号码的拨号器,但允许用户决定是否实际调用电话。 ACTION_DIAL 不需要 CALL_PHONE 权限。

关于android - 如何在 Android 中使用 Intent 调用电话?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4275678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com