Android 拨打电话各安卓版本适用
/**
* 拨打电话
* @param context 上下文对象
* @param phoneNumber 电话号码
*/
public static void callPhone(Context context, String phoneNumber){
//api>23主动获取权限
try {
if (Build.VERSION.SDK_INT >= 23) {
int checkCallPhonePermission = ContextCompat.checkSelfPermission(context,
Manifest.permission.CALL_PHONE);
if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((Activity) context, new String[] {
Manifest.permission.CALL_PHONE
}, 10000);
return;
} else {
//去到拨打电话
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" +phoneNumber));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
} else {
//去到拨打电话
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}catch (ActivityNotFoundException e){
ToastUtils.showShort(R.string.call_failed);
}
}