2013-01-04 9 views
2

ConnectivityManager.getBackgroundDataSetting() for Android 4.0 이상에서 대체로 getActiveNetworkInfo()을 사용하면 변경 (제한)되었을 때 백그라운드 데이터 설정을 따르지 않습니다. 다른 대안이 있습니까? 항상 백그라운드 데이터 설정을 제한하는 경우에도 true를 돌려 "if(connectivityManager.getBackgroundDataSetting()는"4.0 안드로이드 2.3.3을 위해 작동하지만 "if (info.isConnected() == true)"로 대체 할 때 :더 이상 사용되지 않는 ConnectivityManager.getBackgroundDataSetting() 대신 getActiveNetworkInfo()를 사용하면이 값이 적용되지 않습니다.

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

    if(connectivityManager != null) { 
     NetworkInfo info = connectivityManager.getActiveNetworkInfo(); 
     if (info.isConnected() == true) { 
      System.out.println("running"); 
      Toast.makeText(context, "Background settings enabled", Toast.LENGTH_SHORT).show(); 

     } else { 
      System.out.println("active network info null"); 
      System.out.println("enable background services"); 
      Toast.makeText(context, "background settings disabled", Toast.LENGTH_SHORT).show(); 
     } 
    } else { 
     LogUtil.w(getClass(), "Application does not have ACCESS_NETWORK_STATE Permission"); 
    } 

참고 :

다음은 코드입니다.

Reference

답변

0

안드로이드 4.x의 경우에만 확인이 이루어질 때 앱이 포 그라운드에 있지 않을 때 당신이 연결되어 있지 않은 것을 반환합니다. 다른 앱이 포 그라운드에있는 동안 서비스에서이 체크를 할 수 있는지 확인하십시오.