Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android判斷SDK版本及判斷是否聯網

Android判斷SDK版本及判斷是否聯網

編輯:關於Android編程

[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;
 }

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved