2011-11-02 23 views

cevap

7

Bazı güzel ağ kullanım işlevleri Aşağıda benim uygulamaları arasında kullanıyorum, tüm çekicilik gibi çalışır! ve konumu kesinlikle yoklama için - bu yardımcı olur>https://github.com/commonsguy/cwac-locpoll

umut ...

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

yanı getProviders(true); tarafından döndürülen listedeki sağlayıcı mı? Belki de bu cihaz ağ konum sağlayıcısının her zaman bir PASSIVE_PROVIDER sağlamak için etkinleştirilmesi gerektiğini düşünüyor? Bana kırılmış gibi görünüyor. Bu davranışta hangi Samsung cihazlarını görüyorsunuz?

3

Ayrıca böyle deneyebilirsiniz:

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; 
} 
İlgili konular