I have the following code in my program:
public static void callPhoneNumber(Context context, String clientPhoneNum) {
if (isCallingSupported(context)) {
Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + clientPhoneNum));
context.startActivity(i);
} else {
final AlertDialog alertDialog =
new AlertDialog.Builder(context).setMessage(context.getString(R.string.error))
.setMessage(context.getString(R.string.no_call_functionality))
.setPositiveButton(context.getString(R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.create();
alertDialog.show();
}
}
private static boolean isCallingSupported(Context context) {
TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return (telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE);
}
I am wondering if isCallingSupported()
would be necessary at all? I don't remember exactly why I wrote it this way but now when I am reviewing I'm thinking the user may just call a number using his Skype or other VOIP apps. Should I do any other checking instead or is this intent safe without the isCallingSupported()
(what I mean by safe is, even if user has a tablet with no calling functionality and no other apps that can handle a call, the intent doesn't cause a crash)?