亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Android中使用意圖打電話?

如何在Android中使用意圖打電話?

MMTTMM 2019-07-17 09:54:13
如何在Android中使用意圖打電話?我正在使用下面的代碼在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" />例外11-25 14:47:01.661: ERROR/AndroidRuntime(302): Uncaught handler: thread main exiting due to uncaught exception11-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_PHONE11-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)
查看完整描述

3 回答

?
慕絲7291255

TA貢獻1859條經驗 獲得超6個贊

你可以用Intent.ACTION_DIAL而不是Intent.ACTION_CALL..這顯示了已輸入號碼的撥號程序,但允許用戶決定是否實際撥打電話。ACTION_DIAL不需要CALL_PHONE許可。


查看完整回答
反對 回復 2019-07-17
?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

更優雅的選擇:

String phone = "+34666777888";Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phone, null));startActivity(intent);


查看完整回答
反對 回復 2019-07-17
  • 3 回答
  • 0 關注
  • 488 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號