【发布时间】:2020-04-19 04:09:52
【问题描述】:
我的应用使用 android 权限 action_dial。 如何更改代码使其不需要许可? 我需要能够在没有权限的情况下调用
这是代码:
这篇文章充满了代码,这不是我的错。
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
// Older Version No need to request Permission
String dial = "tel:" + phoneNo;
fragment.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(dial)));
} else {
// Need to request Permission
if (fragment.getActivity() != null) {
if (ContextCompat.checkSelfPermission(fragment.getActivity(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
fragment.requestPermissions(new String[]{
Manifest.permission.CALL_PHONE
}, Constants.REQUEST_CODE__PHONE_CALL_PERMISSION);
} else {
String dial = "tel:" + phoneNo;
fragment.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(dial)));
}
}
}
}
int[] grantResults, Fragment fragment, String phoneNo) {
if (requestCode == Constants.REQUEST_CODE__PHONE_CALL_PERMISSION) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
callPhone(fragment, phoneNo);
} else {
Utils.psLog("Permission not Granted");
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
// Older Version No need to request Permission
String dial = "tel:" + phoneNo;
activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
} else {
// Need to request Permission
if (activity != null) {
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[]{
Manifest.permission.CALL_PHONE
}, Constants.REQUEST_CODE__PHONE_CALL_PERMISSION);
} else {
String dial = "tel:" + phoneNo;
activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
}
}
}
【问题讨论】:
-
您需要从清单中删除权限标签,然后从类中删除与权限相关的代码(checkSelfPermission & requestPermissions...),然后只使用 startActivity 为 Intent.ACTION_DIAL,检查下面的代码或者它也是在你的 if (Build.VERSION.SDK_INT
标签: android android-intent android-phone-call