我的应用使用android权限action_dial。
如何更改代码,使其不需要许可?
我需要能够打电话给没有权限的人 这是代码: 这篇文章里充满了代码,这不是我的错。 答案 0 :(得分:0) 您可以这样做: 但是它将把用户导航到默认的呼叫拨号器应用程序并向其传递电话号码,因此用户应按“呼叫”按钮进行呼叫。它不会直接拨打电话。 答案 1 :(得分:0) 未经许可,无法进行直接通话。
您可以使用所需的号码在应用程序顶部打开拨号程序,用户接下来应单击绿色的呼叫按钮。
为此,请使用此代码
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)));
}
}
}
2 个答案:
Intent intentDial = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "123456789"));
context.startActivity(intentDial);
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumberStr));
startActivity(callIntent);