networkCheckIn函数一致地返回false

时间:2013-02-19 11:07:38

标签: android android-networking android-permissions

这是我的networkCheckIn()函数,它连续返回 false 。我无法调试这个。请给我一些解决方案

  1. networkCheckIn()代码:

    public boolean networkCheckIn(){
    
    try{
    
        ConnectivityManager networkInfo = (ConnectivityManager) getSystemService(MapViewActivity.CONNECTIVITY_SERVICE) ;
        networkInfo.getActiveNetworkInfo().isConnectedOrConnecting() ;
    
        Log.d("1", "Net avail:"
                + networkInfo.getActiveNetworkInfo().isConnectedOrConnecting());
    
        ConnectivityManager cm = (ConnectivityManager) getSystemService(MapViewActivity.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            Log.d("2", "Network available:true");
            return true;
    
        } else {
            Log.d("3", "Network available:false");
            return false;
        }
    
    }catch(Exception e){
        return false ;
    }
     }
    
  2. 函数调用:

    if(!(gps.networkCheckIn() == true)){
        gps.showSettingsAlert("Network", "Network") ;
    }
    
  3. 我在Menifest.xml文件中使用了这两个权限:

  4.   

    uses-permission android:name =“android.permission.INTERNET”

         

    uses-permission android:name =“android.permission.ACCESS_NETWORK_STATE”

    我在手机和模拟器上试过了。它返回false,结果显示互联网的设置;互联网是启用还是禁用。

0 个答案:

没有答案