推荐wifionly 和 dataonly判断方法:
public static boolean isVoiceCapable(Context context) {
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephony != null && telephony.isVoiceCapable();
}
public static boolean isSmsCapable(Context context) {
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephony != null && telephony.isSmsCapable();
}
public boolean isWifiOnlyMode() {
return !isVoiceCapable(getAppContext()) && !isSmsCapable(getAppContext());
}
public boolean isDataOnlyMode() {
return !isVoiceCapable(getAppContext()) && isSmsCapable(getAppContext());
}
wifi only 另外一种判断方式:
public static boolean isWifiOnly(Context context) {
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
Context.CONNECTIVITY_SERVICE);
return (cm != null && cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false);
}
public static boolean isVoiceCapable(Context context) {
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephony != null && telephony.isVoiceCapable();
}
public static boolean isSmsCapable(Context context) {
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephony != null && telephony.isSmsCapable();
}
public boolean isWifiOnlyMode() {
return !isVoiceCapable(getAppContext()) && !isSmsCapable(getAppContext());
}
public boolean isDataOnlyMode() {
return !isVoiceCapable(getAppContext()) && isSmsCapable(getAppContext());
}
wifi only 另外一种判断方式:
public static boolean isWifiOnly(Context context) {
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
Context.CONNECTIVITY_SERVICE);
return (cm != null && cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false);
}
本文提供了一种通过检查设备是否支持语音和短信功能来判断设备是否为WiFiOnly或DataOnly模式的方法,并给出了另一种直接检查网络支持情况来判断WiFiOnly模式的实现。
868

被折叠的 条评论
为什么被折叠?



