Skip to content

Commit

Permalink
fix(android): check if NETWORK_PROVIDER is enabled (#2859)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored May 1, 2020
1 parent c86cfb1 commit f4d5c84
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.getcapacitor.plugin;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;

import com.getcapacitor.JSObject;
Expand Down Expand Up @@ -144,11 +146,18 @@ private void requestLocationUpdates(final PluginCall call) {
int timeout = call.getInt("timeout", 10000);
fusedLocationClient = LocationServices.getFusedLocationProviderClient(getContext());

LocationManager lm = (LocationManager)getContext().getSystemService(Context.LOCATION_SERVICE);
boolean networkEnabled = false;
try {
networkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch(Exception ex) {}
LocationRequest locationRequest = new LocationRequest();
locationRequest.setMaxWaitTime(timeout);
locationRequest.setInterval(10000);
locationRequest.setFastestInterval(5000);
locationRequest.setPriority(enableHighAccuracy ? LocationRequest.PRIORITY_HIGH_ACCURACY : LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
int lowPriority = networkEnabled ? LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY : LocationRequest.PRIORITY_LOW_POWER;
int priority = enableHighAccuracy ? LocationRequest.PRIORITY_HIGH_ACCURACY : lowPriority;
locationRequest.setPriority(priority);

locationCallback = new LocationCallback(){
@Override
Expand Down

0 comments on commit f4d5c84

Please sign in to comment.