Android dataonly、wifionly的判别方式

推荐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);
    }

你可能感兴趣的:(Android dataonly、wifionly的判别方式)