One of our applications is running on Sunmi's T1 and T2 mini's. The application sends back the device's location data using the LocationUtil class below:
public class LocationUtil
{
private static final String TAG = LocationUtil.class.getSimpleName();
private final long UPDATE_INTERVAL_IN_MILLISECONDS = 20000;
private final long FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS = 10000;
private final int REQUEST_CHECK_SETTINGS = 100;
private FusedLocationProviderClient mFusedLocationClient;
private SettingsClient mSettingsClient;
private LocationRequest mLocationRequest;
private LocationSettingsRequest mLocationSettingsRequest;
private LocationCallback mLocationCallback;
private Location mCurrentLocation;
private LocationReceived locReceiveListener;
private boolean gettingUpdatesStarted;
private Context context;
public LocationUtil(){
}
public LocationUtil(Context context)
{
this.context = context;
}
public interface LocationReceived {
void onReceive(Location location);
void onError(String message);
}
private Activity actContext = null;
public void initialise(Activity context) {
this.actContext = context;
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
mSettingsClient = LocationServices.getSettingsClient(context);
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
mLocationSettingsRequest = builder.build();
if (mLocationCallback == null)
{
mLocationCallback = new LocationCallback()
{
@Override
public void onLocationResult(LocationResult locationResult)
{
super.onLocationResult(locationResult);
// location is received
mCurrentLocation = locationResult.getLastLocation();
locReceiveListener.onReceive(mCurrentLocation);
}
@Override
public void onLocationAvailability(LocationAvailability locationAvailability)
{
super.onLocationAvailability(locationAvailability);
}
};
}
}
public void StartLocationUpdater(LocationReceived locReceiveListenerIn){
locReceiveListener = locReceiveListenerIn;
if (!gettingUpdatesStarted)
{
gettingUpdatesStarted = true;
mSettingsClient.checkLocationSettings(mLocationSettingsRequest)
.addOnSuccessListener(new OnSuccessListener<LocationSettingsResponse>()
{
@SuppressLint("MissingPermission")
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse)
{
Log.i(TAG, "All location settings are satisfied.");
mFusedLocationClient.requestLocationUpdates(mLocationRequest,
mLocationCallback, Looper.myLooper());
}
})
.addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
int statusCode = ((ApiException) e).getStatusCode();
gettingUpdatesStarted = false;
switch (statusCode)
{
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.i(TAG, "Location settings are not satisfied. Attempting to upgrade " +
"location settings ");
try {
// Show the dialog by calling startResolutionForResult(), and check the
// result in onActivityResult().
ResolvableApiException rae = (ResolvableApiException) e;
rae.startResolutionForResult((Activity) actContext, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sie) {
Log.i(TAG, "PendingIntent unable to execute request.");
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
String errorMessage = "Location settings are inadequate, and cannot be " +
"fixed here. Fix in Settings.";
Log.e(TAG, errorMessage);
}
}
});
}
}
public void getLastLocation(LocationReceived locReceiveListenerIn) {
locReceiveListener = locReceiveListenerIn;
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
mFusedLocationClient.getLastLocation()
.addOnSuccessListener( new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
if (location != null) {
mCurrentLocation = location;
locReceiveListener.onReceive(mCurrentLocation);
}
else{
locReceiveListener.onError("No location received");
}
}
});
}
public void stopLocationUpdates() {
// Removing location updates
mFusedLocationClient
.removeLocationUpdates(mLocationCallback)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
gettingUpdatesStarted = false;
}
});
}
}
However, it seems that the application only gets location data when a device is connected to WIFI first and then switched back to 3G and 4G. The device does not send any location data when it is first connected to a 3G or 4G network. On testing, the following has been found:
The result is Initial positioning with 3G can be successful, but only slowly. The code used the fusion positioning scheme of GMS. When the device asks for the location information by logging, the device soon gets the location information of the base station. The GMS used the location information of the base station to analyze the longitude and latitude of the device. But three minutes later the GMS process prints the log without location, and your application still has no location information. But after a while, the app was able to get information from the 4G network. Based on the information currently available, it is suspected that there is a problem with the GMS returning the location to the application
Even when using the latest google play services, the location can not be provided