My app uses the android permission action_dial. How to change the code so it doesn't need permission? i need to be able to call witout permission
this is the code:
Its not my fault this post is full of code.
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)));
}
}
}