【发布时间】:2015-01-15 20:25:09
【问题描述】:
我的程序中有以下代码:
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);
}
我想知道isCallingSupported() 是否有必要?我不记得我为什么要这样写,但现在当我回顾时,我想用户可能只是使用他的 Skype 或其他 VOIP 应用程序拨打一个号码。我应该做任何其他检查,还是在没有isCallingSupported() 的情况下这个意图是安全的(我的意思是,即使用户的平板电脑没有呼叫功能并且没有其他可以处理呼叫的应用程序,意图不导致崩溃)?
【问题讨论】: