|
|
@@ -32,6 +32,7 @@ import com.google.android.gms.location.LocationServices;
|
|
|
import com.google.android.gms.tasks.OnCompleteListener;
|
|
|
import com.google.android.gms.tasks.Task;
|
|
|
import com.usai.redant.rautils.R;
|
|
|
+import com.usai.redant.rautils.location.SystemLocation;
|
|
|
import com.usai.redant.rautils.receiver.RABroadcast;
|
|
|
import com.usai.redant.rautils.receiver.RABroadcastReceiver;
|
|
|
import com.usai.redant.rautils.upload.RAUploadManager;
|
|
|
@@ -59,6 +60,8 @@ public abstract class RAService extends Service {
|
|
|
public static final int FLAG_SERVICE_UPLOAD = 1 << 3;
|
|
|
// public static final int FLAG_LOCATION_SERVICE = 1<<1;
|
|
|
|
|
|
+ private static final boolean System_Location_Flag = true;
|
|
|
+
|
|
|
// service setup
|
|
|
protected int service_flag = FLAG_SERVICE_NONE;
|
|
|
private IntentFilter msgFilter = new IntentFilter();
|
|
|
@@ -128,23 +131,35 @@ public abstract class RAService extends Service {
|
|
|
* Sets the location request parameters.
|
|
|
*/
|
|
|
private void createLocationRequest() {
|
|
|
- mLocationRequest = new LocationRequest();
|
|
|
- mLocationRequest.setInterval(DEFAULT_LOCATION_TIMEINTERVAL);
|
|
|
- mLocationRequest.setFastestInterval(DEFAULT_LOCATION_TIMEINTERVAL/2);
|
|
|
- mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
|
|
+
|
|
|
+ if (System_Location_Flag) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ mLocationRequest = new LocationRequest();
|
|
|
+ mLocationRequest.setInterval(DEFAULT_LOCATION_TIMEINTERVAL);
|
|
|
+ mLocationRequest.setFastestInterval(DEFAULT_LOCATION_TIMEINTERVAL/2);
|
|
|
+ mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
private void requestLocationUpdates() {
|
|
|
Log.i(TAG, "Requesting location updates");
|
|
|
-// Utils.setRequestingLocationUpdates(this, true);
|
|
|
+
|
|
|
+ if (System_Location_Flag) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // Utils.setRequestingLocationUpdates(this, true);
|
|
|
// startService(new Intent(getApplicationContext(), LocationUpdatesService.class));
|
|
|
- try {
|
|
|
- mFusedLocationClient.requestLocationUpdates(mLocationRequest,
|
|
|
- mLocationCallback, null);
|
|
|
- } catch (SecurityException unlikely) {
|
|
|
+ try {
|
|
|
+ mFusedLocationClient.requestLocationUpdates(mLocationRequest,
|
|
|
+ mLocationCallback, null);
|
|
|
+ } catch (SecurityException unlikely) {
|
|
|
// Utils.setRequestingLocationUpdates(this, false);
|
|
|
- Log.e(TAG, "Lost location permission. Could not request updates. " + unlikely);
|
|
|
+ Log.e(TAG, "Lost location permission. Could not request updates. " + unlikely);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -154,31 +169,49 @@ public abstract class RAService extends Service {
|
|
|
*/
|
|
|
private void removeLocationUpdates() {
|
|
|
Log.i(TAG, "Removing location updates");
|
|
|
- try {
|
|
|
- mFusedLocationClient.removeLocationUpdates(mLocationCallback);
|
|
|
+
|
|
|
+ if (System_Location_Flag) {
|
|
|
+
|
|
|
+ SystemLocation.sharedLocation().stopRequestLocation();
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ try {
|
|
|
+ mFusedLocationClient.removeLocationUpdates(mLocationCallback);
|
|
|
// Utils.setRequestingLocationUpdates(this, false);
|
|
|
- stopSelf();
|
|
|
- } catch (SecurityException unlikely) {
|
|
|
+ stopSelf();
|
|
|
+ } catch (SecurityException unlikely) {
|
|
|
// Utils.setRequestingLocationUpdates(this, true);
|
|
|
- Log.e(TAG, "Lost location permission. Could not remove updates. " + unlikely);
|
|
|
+ Log.e(TAG, "Lost location permission. Could not remove updates. " + unlikely);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
private void getLastLocation() {
|
|
|
- try {
|
|
|
- mFusedLocationClient.getLastLocation()
|
|
|
- .addOnCompleteListener(new OnCompleteListener<Location>() {
|
|
|
- @Override
|
|
|
- public void onComplete(@NonNull Task<Location> task) {
|
|
|
- if (task.isSuccessful() && task.getResult() != null) {
|
|
|
- mLocation = task.getResult();
|
|
|
- } else {
|
|
|
- Log.w(TAG, "Failed to get location.");
|
|
|
+
|
|
|
+ if (System_Location_Flag) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ try {
|
|
|
+ mFusedLocationClient.getLastLocation()
|
|
|
+ .addOnCompleteListener(new OnCompleteListener<Location>() {
|
|
|
+ @Override
|
|
|
+ public void onComplete(@NonNull Task<Location> task) {
|
|
|
+ if (task.isSuccessful() && task.getResult() != null) {
|
|
|
+ mLocation = task.getResult();
|
|
|
+ } else {
|
|
|
+ Log.w(TAG, "Failed to get location.");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (SecurityException unlikely) {
|
|
|
- Log.e(TAG, "Lost location permission." + unlikely);
|
|
|
+ });
|
|
|
+ } catch (SecurityException unlikely) {
|
|
|
+ Log.e(TAG, "Lost location permission." + unlikely);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
// sub function Notification
|
|
|
protected String url_checknotification = null;
|
|
|
@@ -574,29 +607,44 @@ public abstract class RAService extends Service {
|
|
|
|
|
|
}
|
|
|
|
|
|
-public void initLocation()
|
|
|
- {
|
|
|
- if(mFusedLocationClient!=null)
|
|
|
- return;
|
|
|
- mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
|
|
+ public void initLocation() {
|
|
|
|
|
|
- mLocationCallback = new LocationCallback() {
|
|
|
- @Override
|
|
|
- public void onLocationResult(LocationResult locationResult) {
|
|
|
- super.onLocationResult(locationResult);
|
|
|
+ if (System_Location_Flag) {
|
|
|
+
|
|
|
+ SystemLocation.sharedLocation().adjustLocation = true;
|
|
|
+ SystemLocation.sharedLocation().requestLocation(getApplicationContext(), new SystemLocation.SystemLocationChangeCallback() {
|
|
|
+ @Override
|
|
|
+ public void onLocationChanged(Location location) {
|
|
|
+
|
|
|
+ Log.d(TAG, "onLocationChanged: " + location);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- Log.i(TAG, "onLocationResult: " + locationResult.getLastLocation());
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if(mFusedLocationClient!=null)
|
|
|
+ return;
|
|
|
+ mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
|
|
+
|
|
|
+ mLocationCallback = new LocationCallback() {
|
|
|
+ @Override
|
|
|
+ public void onLocationResult(LocationResult locationResult) {
|
|
|
+ super.onLocationResult(locationResult);
|
|
|
+
|
|
|
+ Log.i(TAG, "onLocationResult: " + locationResult.getLastLocation());
|
|
|
// onNewLocation(locationResult.getLastLocation());
|
|
|
- }
|
|
|
- };
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- createLocationRequest();
|
|
|
- getLastLocation();
|
|
|
+ createLocationRequest();
|
|
|
+ getLastLocation();
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
-// enable_locationTracing();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void onDestroy() {
|
|
|
Log.e("_SERVICE", "onDestroy: ");
|
|
|
@@ -810,8 +858,16 @@ public void initLocation()
|
|
|
|
|
|
|
|
|
void disable_locationTracing() {
|
|
|
- removeLocationUpdates();
|
|
|
+
|
|
|
+ if (System_Location_Flag) {
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ removeLocationUpdates();
|
|
|
// locationManager.removeUpdates(locationListener);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -828,8 +884,12 @@ public void initLocation()
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- initLocation();
|
|
|
- requestLocationUpdates();
|
|
|
+ if (System_Location_Flag) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ initLocation();
|
|
|
+ requestLocationUpdates();
|
|
|
// locationManager.requestLocationUpdates(
|
|
|
// "fused", timeInterval, distance,
|
|
|
// locationListener);
|
|
|
@@ -847,6 +907,9 @@ public void initLocation()
|
|
|
// locationListener);
|
|
|
//
|
|
|
// }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
protected Location request_cachedlocation() {
|
|
|
@@ -864,6 +927,12 @@ public void initLocation()
|
|
|
}
|
|
|
|
|
|
protected void request_location(final String receiverID) {
|
|
|
+
|
|
|
+ if (System_Location_Flag) {
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (receiverID == null)
|
|
|
throw new IllegalArgumentException("receiverID can't be null");
|
|
|
|