2011-11-02 39 views

回答

7

下面附加了一些很好的網絡實用功能,我一直在使用我的應用程序,所有的作品都像一個魅力! 和位置查詢,肯定是 - >https://github.com/commonsguy/cwac-locpoll

希望這有助於...

public static boolean checkInternetConnection(Context context) { 

    ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); 

    // ARE WE CONNECTED TO THE NET? 
    if (conMgr.getActiveNetworkInfo() != null 
      && conMgr.getActiveNetworkInfo().isAvailable() 
      && conMgr.getActiveNetworkInfo().isConnected()) { 
     return true; 
    } else { 
     Log.w(TAG, "Internet Connection NOT Present"); 
     return false; 
    } 
} 
    public static boolean isConnAvailAndNotRoaming(Context context) { 

    ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); 

    if (conMgr.getActiveNetworkInfo() != null 
      && conMgr.getActiveNetworkInfo().isAvailable() 
      && conMgr.getActiveNetworkInfo().isConnected()) { 

     if(!conMgr.getActiveNetworkInfo().isRoaming()) 
      return true; 
     else 
      return false; 
    } else { 
     Log.w(TAG, "Internet Connection NOT Present"); 
     return false; 
    } 
} 
    public static boolean isRoaming(Context context) { 

    ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); 

    return (conMgr.getActiveNetworkInfo()!=null && conMgr.getActiveNetworkInfo().isRoaming()); 
} 
0

在由getProviders(true);返回以及列表中的供應商?也許該設備認爲應始終啓用網絡位置提供程序以提供PASSIVE_PROVIDER?似乎打破了我。哪些三星設備你看到這種行爲?

3

您也可以嘗試這樣的:

public boolean isDataConnectionAvailable(Context context){ 
     ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); 
     NetworkInfo info = connectivityManager.getActiveNetworkInfo(); 
     if(info == null) 
      return false; 

     return connectivityManager.getActiveNetworkInfo().isConnected(); 
} 

public boolean isGpsEnabled(LocationManager manager){ 
     if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { 
      return false; 
     } 
     return true; 
} 

public boolean isLocationByNetworkEnabled(LocationManager manager){ 
     if (!manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { 
      return false; 
     } 
     return true; 
} 
相關問題