当前位置:操作系统 > 安卓/Android >>

Android判断SDK版本及判断是否联网

[java]
public static int getSDKVersionNumber() { 
 
        int sdkVersion; 
        try { 
            sdkVersion = Integer.valueOf(android.os.Build.VERSION.SDK); 
 
        } catch (NumberFormatException e) { 
 
            sdkVersion = 0; 
        } 
        return sdkVersion; 
    } 

public static int getSDKVersionNumber() {

  int sdkVersion;
  try {
   sdkVersion = Integer.valueOf(android.os.Build.VERSION.SDK);

  } catch (NumberFormatException e) {

   sdkVersion = 0;
  }
  return sdkVersion;
 }
[java]
public static boolean hasInternet(Activity activity) { 
        ConnectivityManager manager = (ConnectivityManager) activity 
                .getSystemService(Context.CONNECTIVITY_SERVICE); 
        NetworkInfo info = manager.getActiveNetworkInfo(); 
        if (info == null || !info.isConnected()) { 
            return false; 
        } 
        if (info.isRoaming()) { 
            return true; 
        } 
        return true; 
    } 

public static boolean hasInternet(Activity activity) {
  ConnectivityManager manager = (ConnectivityManager) activity
    .getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo info = manager.getActiveNetworkInfo();
  if (info == null || !info.isConnected()) {
   return false;
  }
  if (info.isRoaming()) {
   return true;
  }
  return true;
 }

 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,