title: prompt the user to activate gps in a background service?
body: <p>The main activity is destroyed the first time the app is installed and after that I've got a background service that runs whenever there is available internet. </p>
  
  <p>The background service detects location (amongst other things) and since the app is supposed to remain on the phone for months (it only works when there is internet and not all the time or else that'd drain the battery even further) well since it runs for a long time, the user can disable gps and forget to turn it back on before he is connected to internet the next time which can cause the app to crash when the google API client requests location so for now, the background app automatically opens the settings interface when it detects that gps is off in order to remind the user to turn it on but this solution isn't that good since the interface appears out of nowhere and the user can get confused. </p>
  
  <p>So I want to make a prompt/alert dialogue that tells the user "the app [appName] requires gsp please turn it on" with "yes" and "no" choices and when the user clicks "yes" then the settings interface is shown. Is this doable ? Again, I'm not looking for a solution with an activity as I already know how to do this (no transparent activity either just using the service)</p>
  
  <p><strong>Here's how I'm doing things so far:</strong></p>
  
  <pre><code>//This part of the code is right before getting the current location
      if (!isLocationEnabled(this)) {
  
                Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(myIntent);
  
          }
  
      public static boolean isLocationEnabled(Context context) {
          int locationMode = 0;
          String locationProviders;
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {
              try {
                  locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
  
              } catch (Settings.SettingNotFoundException e) {
                  e.printStackTrace();
                  return false;
              }
  
              return locationMode != Settings.Secure.LOCATION_MODE_OFF;
  
          } else {
              locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
              return !TextUtils.isEmpty(locationProviders);
          }
  
  
      }
  </code></pre>