title: android GPS BroadCastReceiver for up Api 26
body: <p>I am trying handle detect When Gps on/of,When I use below codes,it works until Api 26,but in Android 8.0 and Android 9.0 doesn't work.How can I fix code to provide working in android 8.0 and 9.0?</p>
  
  <p>GpsLocationReceiver class</p>
  
  <pre><code>public class GpsLocationReceiver extends BroadcastReceiver {
  
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          if (intent.getAction().matches("android.location.PROVIDERS_CHANGED")) {
  
              LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
              boolean isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
              boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  
              if (isGpsEnabled || isNetworkEnabled) {
  
                  Toast.makeText(context, "in android.location.PROVIDERS_OPen",
                          Toast.LENGTH_SHORT).show();
              } else {
  
                  // Handle Location turned OFF
                  Intent pushIntent = new Intent(context, AlertMessage.class);
                  pushIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  context.startActivity(pushIntent);
              }
  
  
          }
      }
  }
  </code></pre>
  
  <p>Android Manifests</p>
  
  <pre><code>&lt;receiver android:name=".service.GpsLocationReceiver"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.location.PROVIDERS_CHANGED" /&gt;
  
          &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>