android 调用拨打电话,程序崩溃

男儿欲遂平生志,六经勤向窗前读。这篇文章主要讲述android 调用拨打电话,程序崩溃相关的知识,希望能为你提供帮助。
FATAL EXCEPTION: main
03-27 17:43:08.012: E/androidRuntime(18523): Process: com.mtq.freighthelper, PID: 18523
03-27 17:43:08.012: E/AndroidRuntime(18523): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxx-xxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{1f529f5 18523:com.mtq.freighthelper/u0a491} (pid=18523, uid=10491) with revoked permission android.permission.CALL_PHONE
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.os.Parcel.readException(Parcel.java:1620)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.os.Parcel.readException(Parcel.java:1573)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2681)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1509)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.app.Activity.startActivityForResult(Activity.java:3978)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.app.Activity.startActivityForResult(Activity.java:3939)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.app.Activity.startActivity(Activity.java:4262)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.app.Activity.startActivity(Activity.java:4230)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at com.mtq.freighthelper.ui.activity.contacts.ContactsDetailActivity.onClick(ContactsDetailActivity.java:97)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.view.View.performClick(View.java:5207)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.view.View$PerformClick.run(View.java:21177)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.os.Handler.handleCallback(Handler.java:739)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.os.Handler.dispatchMessage(Handler.java:95)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.os.Looper.loop(Looper.java:148)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at android.app.ActivityThread.main(ActivityThread.java:5438)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at java.lang.reflect.Method.invoke(Native Method)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
03-27 17:43:08.012: E/AndroidRuntime(18523):       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
 
使用设备:小米4
android: 6.0
程序报java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxx-xxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{1f529f5 18523:com.mtq.freighthelper/u0a491} (pid=18523, uid=10491) with revoked permission
【android 调用拨打电话,程序崩溃】原因:
在6.0 系统中请求某些权限需要检查权限
 

1 if (!TextUtils.isEmpty(phone)) { 2if (!hasPermission()) { 3// 在6.0 系统中请求某些权限需要检查权限 4int curApiVersion = Build.VERSION.SDK_INT; 5if (curApiVersion > = Build.VERSION_CODES.M) { 6// 动态请求拨打电话权限 7requestPermissions( 8new String[] { Manifest.permission.CALL_PHONE }, 90x11); 10} else { 11intentToCall(phone); 12} 13} else { 14intentToCall(phone); 15} 16}

 
1 private boolean hasPermission() { 2if (checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { 3return false; 4} 5return true; 6} 7 8private void intentToCall(String phoneNumber) { 9Intent intent = new Intent(Intent.ACTION_CALL); 10Uri data = https://www.songbingjia.com/android/Uri.parse("tel:" + phoneNumber); 11intent.setData(data); 12startActivity(intent); 13} 14 15 16/** 17* 动态请求拨打电话权限后,监听用户的点击事件 18*/ 19@Override 20public void onRequestPermissionsResult(int requestCode, 21String[] permissions, int[] grantResults) { 22super.onRequestPermissionsResult(requestCode, permissions, grantResults); 23if (requestCode == 0x11) { 24// If request is cancelled, the result arrays are empty. 25if (grantResults.length > 0 26& & grantResults[0] == PackageManager.PERMISSION_GRANTED) { 27CldLog.i("CMCC", "权限被允许"); 28String phone = mContactsInfo.getPhone(); 29intentToCall(phone); 30} else { 31CldLog.i("CMCC", "权限被拒绝"); 32} 33} 34}

 





















    推荐阅读