|
@@ -17,19 +17,19 @@ import android.os.Binder;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
|
-import android.support.annotation.NonNull;
|
|
|
|
|
-import android.support.v4.app.ActivityCompat;
|
|
|
|
|
-import android.support.v4.app.NotificationCompat;
|
|
|
|
|
|
|
+import androidx.annotation.NonNull;
|
|
|
|
|
+import androidx.core.app.ActivityCompat;
|
|
|
|
|
+import androidx.core.app.NotificationCompat;
|
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
-import com.google.android.gms.location.FusedLocationProviderClient;
|
|
|
|
|
-import com.google.android.gms.location.LocationCallback;
|
|
|
|
|
-import com.google.android.gms.location.LocationRequest;
|
|
|
|
|
-import com.google.android.gms.location.LocationResult;
|
|
|
|
|
-import com.google.android.gms.location.LocationServices;
|
|
|
|
|
-import com.google.android.gms.tasks.OnCompleteListener;
|
|
|
|
|
-import com.google.android.gms.tasks.Task;
|
|
|
|
|
|
|
+//import com.google.android.gms.location.FusedLocationProviderClient;
|
|
|
|
|
+//import com.google.android.gms.location.LocationCallback;
|
|
|
|
|
+//import com.google.android.gms.location.LocationRequest;
|
|
|
|
|
+//import com.google.android.gms.location.LocationResult;
|
|
|
|
|
+//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.R;
|
|
|
import com.usai.redant.rautils.location.SystemLocation;
|
|
import com.usai.redant.rautils.location.SystemLocation;
|
|
|
import com.usai.redant.rautils.receiver.RABroadcast;
|
|
import com.usai.redant.rautils.receiver.RABroadcast;
|
|
@@ -109,33 +109,36 @@ public abstract class RAService extends Service {
|
|
|
// LocationListener locationListener = null;
|
|
// LocationListener locationListener = null;
|
|
|
// LocationManager locationManager = null;
|
|
// LocationManager locationManager = null;
|
|
|
|
|
|
|
|
- private LocationRequest mLocationRequest;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Provides access to the Fused Location Provider API.
|
|
|
|
|
- */
|
|
|
|
|
- private FusedLocationProviderClient mFusedLocationClient;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Callback for changes in location.
|
|
|
|
|
- */
|
|
|
|
|
- private LocationCallback mLocationCallback;
|
|
|
|
|
-
|
|
|
|
|
-// private Handler mServiceHandler;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * The current location.
|
|
|
|
|
- */
|
|
|
|
|
- private Location mLocation;
|
|
|
|
|
-
|
|
|
|
|
-// int locationTracing_timeInterval = DEFAULT_LOCATION_TIMEINTERVAL;
|
|
|
|
|
-// int locationTracing_distance = DEFAULT_DISTANCE;
|
|
|
|
|
- // protected abstract void onLocationChanged(Location location);
|
|
|
|
|
- private ServiceLocation locationCallback = null;
|
|
|
|
|
|
|
+ //============= 定位会移动到单独的lib中===========
|
|
|
|
|
|
|
|
|
|
+//
|
|
|
|
|
+// private LocationRequest mLocationRequest;
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * Provides access to the Fused Location Provider API.
|
|
|
|
|
+// */
|
|
|
|
|
+// private FusedLocationProviderClient mFusedLocationClient;
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * Callback for changes in location.
|
|
|
|
|
+// */
|
|
|
|
|
+// private LocationCallback mLocationCallback;
|
|
|
|
|
+//
|
|
|
|
|
+//// private Handler mServiceHandler;
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * The current location.
|
|
|
|
|
+// */
|
|
|
|
|
+// private Location mLocation;
|
|
|
|
|
+//
|
|
|
|
|
+//// int locationTracing_timeInterval = DEFAULT_LOCATION_TIMEINTERVAL;
|
|
|
|
|
+//// int locationTracing_distance = DEFAULT_DISTANCE;
|
|
|
|
|
+// // protected abstract void onLocationChanged(Location location);
|
|
|
|
|
+// private ServiceLocation locationCallback = null;
|
|
|
|
|
+//
|
|
|
public interface ServiceLocation {
|
|
public interface ServiceLocation {
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+//此类将去掉
|
|
|
public abstract Location RequestCachedLocation();
|
|
public abstract Location RequestCachedLocation();
|
|
|
// public abstract void RequestLocation_ByBroadcast(String receiverID);
|
|
// public abstract void RequestLocation_ByBroadcast(String receiverID);
|
|
|
|
|
|
|
@@ -143,106 +146,111 @@ public abstract class RAService extends Service {
|
|
|
// public abstract void onLogin();
|
|
// public abstract void onLogin();
|
|
|
// public abstract void onLogout();
|
|
// public abstract void onLogout();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+//
|
|
|
public void initServiceLocation(boolean systemLocation, ServiceLocation locationCallback) {
|
|
public void initServiceLocation(boolean systemLocation, ServiceLocation locationCallback) {
|
|
|
- System_Location_Flag = systemLocation;
|
|
|
|
|
-
|
|
|
|
|
- service_flag = service_flag | FLAG_SERVICE_LOCATION;
|
|
|
|
|
- this.locationCallback = locationCallback;
|
|
|
|
|
- }
|
|
|
|
|
- /**
|
|
|
|
|
- * Sets the location request parameters.
|
|
|
|
|
- */
|
|
|
|
|
- private void createLocationRequest() {
|
|
|
|
|
-
|
|
|
|
|
- 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");
|
|
|
|
|
-
|
|
|
|
|
- if (System_Location_Flag) {
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- // Utils.setRequestingLocationUpdates(this, true);
|
|
|
|
|
-// startService(new Intent(getApplicationContext(), LocationUpdatesService.class));
|
|
|
|
|
- try {
|
|
|
|
|
-
|
|
|
|
|
- Log.d(TAG, "requestLocationUpdates: ");
|
|
|
|
|
-// long dbg_l = mLocationRequest.getNumUpdates();
|
|
|
|
|
-// if(backgroundLocationTracing)
|
|
|
|
|
-// mLocationRequest.setNumUpdates(0);
|
|
|
|
|
-// else
|
|
|
|
|
-// mLocationRequest.setNumUpdates(1);
|
|
|
|
|
- mFusedLocationClient.requestLocationUpdates(mLocationRequest,
|
|
|
|
|
- mLocationCallback, null);
|
|
|
|
|
- } catch (SecurityException unlikely) {
|
|
|
|
|
-// Utils.setRequestingLocationUpdates(this, false);
|
|
|
|
|
- Log.e(TAG, "Lost location permission. Could not request updates. " + unlikely);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Removes location updates. Note that in this sample we merely log the
|
|
|
|
|
- * {@link SecurityException}.
|
|
|
|
|
- */
|
|
|
|
|
- private void removeLocationUpdates() {
|
|
|
|
|
- Log.i(TAG, "Removing location updates");
|
|
|
|
|
-
|
|
|
|
|
- if (System_Location_Flag) {
|
|
|
|
|
-
|
|
|
|
|
- SystemLocation.sharedLocation().stopRequestLocation();
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- mFusedLocationClient.removeLocationUpdates(mLocationCallback);
|
|
|
|
|
-// Utils.setRequestingLocationUpdates(this, false);
|
|
|
|
|
- stopSelf();
|
|
|
|
|
- } catch (SecurityException unlikely) {
|
|
|
|
|
-// Utils.setRequestingLocationUpdates(this, true);
|
|
|
|
|
- Log.e(TAG, "Lost location permission. Could not remove updates. " + unlikely);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
+ return ;//此接口将去掉
|
|
|
|
|
+// System_Location_Flag = systemLocation;
|
|
|
|
|
+//
|
|
|
|
|
+// service_flag = service_flag | FLAG_SERVICE_LOCATION;
|
|
|
|
|
+// this.locationCallback = locationCallback;
|
|
|
}
|
|
}
|
|
|
- private void getLastLocation() {
|
|
|
|
|
-
|
|
|
|
|
- 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);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// /**
|
|
|
|
|
+// * Sets the location request parameters.
|
|
|
|
|
+// */
|
|
|
|
|
+// private void createLocationRequest() {
|
|
|
|
|
+//
|
|
|
|
|
+// 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");
|
|
|
|
|
+//
|
|
|
|
|
+// if (System_Location_Flag) {
|
|
|
|
|
+//
|
|
|
|
|
+// } else {
|
|
|
|
|
+//
|
|
|
|
|
+// // Utils.setRequestingLocationUpdates(this, true);
|
|
|
|
|
+//// startService(new Intent(getApplicationContext(), LocationUpdatesService.class));
|
|
|
|
|
+// try {
|
|
|
|
|
+//
|
|
|
|
|
+// Log.d(TAG, "requestLocationUpdates: ");
|
|
|
|
|
+//// long dbg_l = mLocationRequest.getNumUpdates();
|
|
|
|
|
+//// if(backgroundLocationTracing)
|
|
|
|
|
+//// mLocationRequest.setNumUpdates(0);
|
|
|
|
|
+//// else
|
|
|
|
|
+//// mLocationRequest.setNumUpdates(1);
|
|
|
|
|
+// mFusedLocationClient.requestLocationUpdates(mLocationRequest,
|
|
|
|
|
+// mLocationCallback, null);
|
|
|
|
|
+// } catch (SecurityException unlikely) {
|
|
|
|
|
+//// Utils.setRequestingLocationUpdates(this, false);
|
|
|
|
|
+// Log.e(TAG, "Lost location permission. Could not request updates. " + unlikely);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * Removes location updates. Note that in this sample we merely log the
|
|
|
|
|
+// * {@link SecurityException}.
|
|
|
|
|
+// */
|
|
|
|
|
+// private void removeLocationUpdates() {
|
|
|
|
|
+// Log.i(TAG, "Removing location updates");
|
|
|
|
|
+//
|
|
|
|
|
+// if (System_Location_Flag) {
|
|
|
|
|
+//
|
|
|
|
|
+// SystemLocation.sharedLocation().stopRequestLocation();
|
|
|
|
|
+//
|
|
|
|
|
+// } else {
|
|
|
|
|
+//
|
|
|
|
|
+// try {
|
|
|
|
|
+// mFusedLocationClient.removeLocationUpdates(mLocationCallback);
|
|
|
|
|
+//// Utils.setRequestingLocationUpdates(this, false);
|
|
|
|
|
+// stopSelf();
|
|
|
|
|
+// } catch (SecurityException unlikely) {
|
|
|
|
|
+//// Utils.setRequestingLocationUpdates(this, true);
|
|
|
|
|
+// Log.e(TAG, "Lost location permission. Could not remove updates. " + unlikely);
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+// private void getLastLocation() {
|
|
|
|
|
+//
|
|
|
|
|
+// 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);
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
// sub function Notification
|
|
// sub function Notification
|
|
|
protected String url_checknotification = null;
|
|
protected String url_checknotification = null;
|
|
|
int pushcheck_timeInterval = DEFAULT_PUSHNOTIFICATION_TIMEINTERVAL;
|
|
int pushcheck_timeInterval = DEFAULT_PUSHNOTIFICATION_TIMEINTERVAL;
|
|
@@ -468,12 +476,12 @@ public abstract class RAService extends Service {
|
|
|
// for ActivityCompat#requestPermissions for more details.
|
|
// for ActivityCompat#requestPermissions for more details.
|
|
|
// return;
|
|
// return;
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
-
|
|
|
|
|
- initLocation();
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// else
|
|
|
|
|
+// {
|
|
|
|
|
+//
|
|
|
|
|
+// initLocation();
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
return super.onStartCommand(intent,flags,startId);
|
|
return super.onStartCommand(intent,flags,startId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -569,29 +577,29 @@ public abstract class RAService extends Service {
|
|
|
// for ActivityCompat#requestPermissions for more details.
|
|
// for ActivityCompat#requestPermissions for more details.
|
|
|
// return;
|
|
// return;
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
-
|
|
|
|
|
- initLocation();
|
|
|
|
|
-// 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();
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
|
|
+// else
|
|
|
|
|
+// {
|
|
|
//
|
|
//
|
|
|
-// enable_locationTracing();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// initLocation();
|
|
|
|
|
+//// 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();
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// enable_locationTracing();
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -641,73 +649,76 @@ public abstract class RAService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- private void setCurrentLocation(Location location) {
|
|
|
|
|
- mCurrentLocation = location;
|
|
|
|
|
- if (location != null) {
|
|
|
|
|
- mLastNotNullLocation = location;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (locationCallback != null) {
|
|
|
|
|
- locationCallback.onLocationChanged(location);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+//
|
|
|
|
|
+// private void setCurrentLocation(Location location) {
|
|
|
|
|
+// mCurrentLocation = location;
|
|
|
|
|
+// if (location != null) {
|
|
|
|
|
+// mLastNotNullLocation = location;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// if (locationCallback != null) {
|
|
|
|
|
+// locationCallback.onLocationChanged(location);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
public Location getCurrentLocation() {
|
|
public Location getCurrentLocation() {
|
|
|
- if ((service_flag & FLAG_SERVICE_LOCATION) == FLAG_SERVICE_LOCATION) {
|
|
|
|
|
- return mCurrentLocation;
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ return null;// 此接口将去掉
|
|
|
|
|
+// if ((service_flag & FLAG_SERVICE_LOCATION) == FLAG_SERVICE_LOCATION) {
|
|
|
|
|
+// return mCurrentLocation;
|
|
|
|
|
+// }
|
|
|
|
|
+// return null;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+//
|
|
|
public Location getLastKnownLocation() {
|
|
public Location getLastKnownLocation() {
|
|
|
- if ((service_flag & FLAG_SERVICE_LOCATION) == FLAG_SERVICE_LOCATION) {
|
|
|
|
|
- return mLastNotNullLocation;
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void initLocation() {
|
|
|
|
|
-
|
|
|
|
|
- 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);
|
|
|
|
|
- setCurrentLocation(location);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- if(mFusedLocationClient!=null)
|
|
|
|
|
- return;
|
|
|
|
|
- Log.d(TAG, "initLocation: ");
|
|
|
|
|
- mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
|
|
|
|
-
|
|
|
|
|
- mLocationCallback = new LocationCallback() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onLocationResult(LocationResult locationResult) {
|
|
|
|
|
- super.onLocationResult(locationResult);
|
|
|
|
|
-
|
|
|
|
|
- Log.i(TAG, "FusedLocationClient onLocationResult: " + locationResult.getLastLocation());
|
|
|
|
|
-// onNewLocation(locationResult.getLastLocation());
|
|
|
|
|
-
|
|
|
|
|
- Location location = locationResult.getLastLocation();
|
|
|
|
|
- setCurrentLocation(location);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- createLocationRequest();
|
|
|
|
|
- getLastLocation();
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
+ return null; // 此接口将去掉
|
|
|
|
|
+// if ((service_flag & FLAG_SERVICE_LOCATION) == FLAG_SERVICE_LOCATION) {
|
|
|
|
|
+// return mLastNotNullLocation;
|
|
|
|
|
+// }
|
|
|
|
|
+// return null;
|
|
|
}
|
|
}
|
|
|
|
|
+//
|
|
|
|
|
+// public void initLocation() {
|
|
|
|
|
+//
|
|
|
|
|
+// 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);
|
|
|
|
|
+// setCurrentLocation(location);
|
|
|
|
|
+// }
|
|
|
|
|
+// });
|
|
|
|
|
+//
|
|
|
|
|
+// } else {
|
|
|
|
|
+//
|
|
|
|
|
+// if(mFusedLocationClient!=null)
|
|
|
|
|
+// return;
|
|
|
|
|
+// Log.d(TAG, "initLocation: ");
|
|
|
|
|
+// mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
|
|
|
|
+//
|
|
|
|
|
+// mLocationCallback = new LocationCallback() {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void onLocationResult(LocationResult locationResult) {
|
|
|
|
|
+// super.onLocationResult(locationResult);
|
|
|
|
|
+//
|
|
|
|
|
+// Log.i(TAG, "FusedLocationClient onLocationResult: " + locationResult.getLastLocation());
|
|
|
|
|
+//// onNewLocation(locationResult.getLastLocation());
|
|
|
|
|
+//
|
|
|
|
|
+// Location location = locationResult.getLastLocation();
|
|
|
|
|
+// setCurrentLocation(location);
|
|
|
|
|
+// }
|
|
|
|
|
+// };
|
|
|
|
|
+//
|
|
|
|
|
+// createLocationRequest();
|
|
|
|
|
+// getLastLocation();
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -759,24 +770,27 @@ public abstract class RAService extends Service {
|
|
|
reachabilityCallback.networkStateChanged(networkInfo);
|
|
reachabilityCallback.networkStateChanged(networkInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- } else
|
|
|
|
|
- if (RABroadcast.ACTION_LOCATION_ENABLE_TRACING.equals(action)) {
|
|
|
|
|
- enable_locationTracing();
|
|
|
|
|
- } else
|
|
|
|
|
- if (RABroadcast.ACTION_LOCATION_DISABLE_TRACING
|
|
|
|
|
- .equals(action)) {
|
|
|
|
|
-
|
|
|
|
|
- disable_locationTracing();
|
|
|
|
|
- } else
|
|
|
|
|
- if (RABroadcast.ACTION_LOCATION_REQUEST_LOCATION
|
|
|
|
|
- .equals(action)) {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- String receiverID = intent.getStringExtra("receiverID");
|
|
|
|
|
-// locationManager.requestSingleUpdate();
|
|
|
|
|
- request_location(receiverID);
|
|
|
|
|
-// locationCallback.onLocationChanged();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //=============去掉 servicelocation==================
|
|
|
|
|
+// else
|
|
|
|
|
+// if (RABroadcast.ACTION_LOCATION_ENABLE_TRACING.equals(action)) {
|
|
|
|
|
+// enable_locationTracing();
|
|
|
|
|
+// } else
|
|
|
|
|
+// if (RABroadcast.ACTION_LOCATION_DISABLE_TRACING
|
|
|
|
|
+// .equals(action)) {
|
|
|
|
|
+//
|
|
|
|
|
+// disable_locationTracing();
|
|
|
|
|
+// } else
|
|
|
|
|
+// if (RABroadcast.ACTION_LOCATION_REQUEST_LOCATION
|
|
|
|
|
+// .equals(action)) {
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// String receiverID = intent.getStringExtra("receiverID");
|
|
|
|
|
+//// locationManager.requestSingleUpdate();
|
|
|
|
|
+// request_location(receiverID);
|
|
|
|
|
+//// locationCallback.onLocationChanged();
|
|
|
|
|
+// }
|
|
|
/*
|
|
/*
|
|
|
else if (RABroadcast.ACTION_PUSHNOTIFICATION_CHECK.equals(action)) {
|
|
else if (RABroadcast.ACTION_PUSHNOTIFICATION_CHECK.equals(action)) {
|
|
|
|
|
|
|
@@ -894,129 +908,133 @@ public abstract class RAService extends Service {
|
|
|
//
|
|
//
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- void disable_locationTracing() {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- backgroundLocationTracing = false;
|
|
|
|
|
- if (System_Location_Flag) {
|
|
|
|
|
-
|
|
|
|
|
- removeLocationUpdates();
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- removeLocationUpdates();
|
|
|
|
|
-// locationManager.removeUpdates(locationListener);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- void enable_locationTracing() {
|
|
|
|
|
-
|
|
|
|
|
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
- // TODO: Consider calling
|
|
|
|
|
- // ActivityCompat#requestPermissions
|
|
|
|
|
- // here to request the missing permissions, and then overriding
|
|
|
|
|
- // public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
|
|
|
|
- // int[] grantResults)
|
|
|
|
|
- // to handle the case where the user grants the permission. See the documentation
|
|
|
|
|
- // for ActivityCompat#requestPermissions for more details.
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- backgroundLocationTracing = true;
|
|
|
|
|
- if (System_Location_Flag) {
|
|
|
|
|
-
|
|
|
|
|
- initLocation();
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- Log.d(TAG, "enable_locationTracing: ");
|
|
|
|
|
- initLocation();
|
|
|
|
|
- requestLocationUpdates();
|
|
|
|
|
-// locationManager.requestLocationUpdates(
|
|
|
|
|
-// "fused", timeInterval, distance,
|
|
|
|
|
-// locationListener);
|
|
|
|
|
-// if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
|
|
|
|
|
|
+//========= 去掉 service location====================
|
|
|
//
|
|
//
|
|
|
|
|
+// void disable_locationTracing() {
|
|
|
//
|
|
//
|
|
|
//
|
|
//
|
|
|
|
|
+// backgroundLocationTracing = false;
|
|
|
|
|
+// if (System_Location_Flag) {
|
|
|
//
|
|
//
|
|
|
-// } else if (locationManager
|
|
|
|
|
-// .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
|
|
|
|
|
|
+// removeLocationUpdates();
|
|
|
//
|
|
//
|
|
|
|
|
+// } else {
|
|
|
//
|
|
//
|
|
|
-// locationManager.requestLocationUpdates(
|
|
|
|
|
-// LocationManager.NETWORK_PROVIDER, timeInterval, distance,
|
|
|
|
|
-// locationListener);
|
|
|
|
|
//
|
|
//
|
|
|
|
|
+// removeLocationUpdates();
|
|
|
|
|
+//// locationManager.removeUpdates(locationListener);
|
|
|
// }
|
|
// }
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// void enable_locationTracing() {
|
|
|
|
|
+//
|
|
|
|
|
+// if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
+// // TODO: Consider calling
|
|
|
|
|
+// // ActivityCompat#requestPermissions
|
|
|
|
|
+// // here to request the missing permissions, and then overriding
|
|
|
|
|
+// // public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
|
|
|
|
+// // int[] grantResults)
|
|
|
|
|
+// // to handle the case where the user grants the permission. See the documentation
|
|
|
|
|
+// // for ActivityCompat#requestPermissions for more details.
|
|
|
|
|
+// return;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// backgroundLocationTracing = true;
|
|
|
|
|
+// if (System_Location_Flag) {
|
|
|
|
|
+//
|
|
|
|
|
+// initLocation();
|
|
|
|
|
+//
|
|
|
|
|
+// } else {
|
|
|
|
|
+//
|
|
|
|
|
+// Log.d(TAG, "enable_locationTracing: ");
|
|
|
|
|
+// initLocation();
|
|
|
|
|
+// requestLocationUpdates();
|
|
|
|
|
+//// locationManager.requestLocationUpdates(
|
|
|
|
|
+//// "fused", timeInterval, distance,
|
|
|
|
|
+//// locationListener);
|
|
|
|
|
+//// if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// } else if (locationManager
|
|
|
|
|
+//// .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// locationManager.requestLocationUpdates(
|
|
|
|
|
+//// LocationManager.NETWORK_PROVIDER, timeInterval, distance,
|
|
|
|
|
+//// locationListener);
|
|
|
|
|
+////
|
|
|
|
|
+//// }
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
protected Location request_cachedlocation() {
|
|
protected Location request_cachedlocation() {
|
|
|
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
-
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
+ return null; //此接口将去掉
|
|
|
|
|
|
|
|
- //使用GPS获取上一次的地址,这样获取到的信息需要多次,才能够显示出来,所以后面有动态的判断
|
|
|
|
|
-// Location location = locationManager.getLastKnownLocation("fused");
|
|
|
|
|
-// return location;
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+// if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
+//
|
|
|
|
|
+// return null;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// //使用GPS获取上一次的地址,这样获取到的信息需要多次,才能够显示出来,所以后面有动态的判断
|
|
|
|
|
+//// Location location = locationManager.getLastKnownLocation("fused");
|
|
|
|
|
+//// return location;
|
|
|
|
|
+// return null;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected void request_location(final String receiverID) {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if (receiverID == null)
|
|
|
|
|
- throw new IllegalArgumentException("receiverID can't be null");
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
- // TODO: Consider calling
|
|
|
|
|
- // ActivityCompat#requestPermissions
|
|
|
|
|
- // here to request the missing permissions, and then overriding
|
|
|
|
|
- // public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
|
|
|
|
- // int[] grantResults)
|
|
|
|
|
- // to handle the case where the user grants the permission. See the documentation
|
|
|
|
|
- // for ActivityCompat#requestPermissions for more details.
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- backgroundLocationTracing = true;
|
|
|
|
|
- if (System_Location_Flag) {
|
|
|
|
|
-
|
|
|
|
|
- initLocation();
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- initLocation();
|
|
|
|
|
- requestLocationUpdates();
|
|
|
|
|
-// locationManager.requestLocationUpdates(
|
|
|
|
|
-// "fused", timeInterval, distance,
|
|
|
|
|
-// locationListener);
|
|
|
|
|
-// if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
|
|
|
|
|
|
+// protected void request_location(final String receiverID) {
|
|
|
//
|
|
//
|
|
|
//
|
|
//
|
|
|
|
|
+// if (receiverID == null)
|
|
|
|
|
+// throw new IllegalArgumentException("receiverID can't be null");
|
|
|
//
|
|
//
|
|
|
//
|
|
//
|
|
|
-// } else if (locationManager
|
|
|
|
|
-// .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
|
|
|
|
|
|
+// if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
+// // TODO: Consider calling
|
|
|
|
|
+// // ActivityCompat#requestPermissions
|
|
|
|
|
+// // here to request the missing permissions, and then overriding
|
|
|
|
|
+// // public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
|
|
|
|
+// // int[] grantResults)
|
|
|
|
|
+// // to handle the case where the user grants the permission. See the documentation
|
|
|
|
|
+// // for ActivityCompat#requestPermissions for more details.
|
|
|
|
|
+// return;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// backgroundLocationTracing = true;
|
|
|
|
|
+// if (System_Location_Flag) {
|
|
|
//
|
|
//
|
|
|
|
|
+// initLocation();
|
|
|
//
|
|
//
|
|
|
-// locationManager.requestLocationUpdates(
|
|
|
|
|
-// LocationManager.NETWORK_PROVIDER, timeInterval, distance,
|
|
|
|
|
-// locationListener);
|
|
|
|
|
|
|
+// } else {
|
|
|
|
|
+//
|
|
|
|
|
+// initLocation();
|
|
|
|
|
+// requestLocationUpdates();
|
|
|
|
|
+//// locationManager.requestLocationUpdates(
|
|
|
|
|
+//// "fused", timeInterval, distance,
|
|
|
|
|
+//// locationListener);
|
|
|
|
|
+//// if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// } else if (locationManager
|
|
|
|
|
+//// .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// locationManager.requestLocationUpdates(
|
|
|
|
|
+//// LocationManager.NETWORK_PROVIDER, timeInterval, distance,
|
|
|
|
|
+//// locationListener);
|
|
|
|
|
+////
|
|
|
|
|
+//// }
|
|
|
//
|
|
//
|
|
|
// }
|
|
// }
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|