直接看代码吧:
if (!EasyPermissions.hasPermissions(mFragment!!.context!!, *CALL_PHONE)) {
EasyPermissions.requestPermissions(mFragment, mFragment.getString(R.string.call_permission), REQUEST_CODE_CALL_PHONE, *CALL_PHONE)
} else {
UtilHelper.call2(mFragment!!.context!!, tel)
//360手机判断权限方法对它都没有,只好如果2s后,如果拨打电话界面不出来,还是本界面,证明没权限拨打不了
if (Build.MANUFACTURER == "360"){
Observable.timer(2,TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
if (ActivityUtils.isForeground(mActivity)){
appSettingDialog(mActivity, "拨打电话权限")
}
})
}
}
其中
fun call2(activity: Context?, phone: String?) {
if (activity == null || phone.isNullOrBlank()) {
return
}
val intent = Intent(Intent.ACTION_CALL, Uri.parse("tel:$phone"))
if (ContextCompat.checkSelfPermission(activity!!, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
//不具有打电话权限,需要进行权限申请
ToastUtils.showCustomToast("没有电话权限")
return
}
try {
activity.startActivity(intent)
}catch (e:java.lang.Exception){
e.printStackTrace()
}
}
fun appSettingDialog(context: Activity, str: String) {
Toast.makeText(context, "已拒绝权限" + str + "并不再询问", Toast.LENGTH_SHORT).show()
AppSettingsDialog.Builder(context)
.setTitle("永久禁止权限访问")
.setRationale("此功能需要$str,否则无法正常使用,是否打开设置")
.setPositiveButton("好")
.setNegativeButton("不行")
.build()
.show()
}
网友评论