title: Android internet connection problem on sleep mode?
body: <p>I have a service Activity and a thread in it. Problem is when phone go to sleep mode, thread doesnt send http request And i check the network state if it is not connect i work to connect it but i get "Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS" error. But i already put the permission tag in AndroidManifest.xml. I also try this:</p>
  
  <pre><code>PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
  PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK , "TAG");
  wl.acquire();
  </code></pre>
  
  <p>But it is not solve my problem. phone Already go to sleep mode. Here is my checkNetwork code:</p>
  
  <pre><code>private boolean checkNetwork(){
      try{
          Context context = getApplicationContext();
          ConnectivityManager connectivity = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo info = connectivity.getActiveNetworkInfo();
          if(info == null){
              connectivity.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);
              int status = connectivity.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, "cmwap");
              NetworkInfo info1 = connectivity.getActiveNetworkInfo();
              return false;
          }
          if (info.getState() == NetworkInfo.State.CONNECTED )
              return true;
          return false;
  
      }catch(Exception ex){
          return false;
      }
  }
  </code></pre>
  
  <p>public class MainActivity extends Service {
  .....</p>
  
  <pre><code>private Runnable httpThread = new Runnable() {
  
          public void run() {
  //i send http request here
  }
  }
  </code></pre>
  
  <p>Please help..</p>