We have external Bluetooth device, that delivers different type of data to android device. Among others it delivers also GPS NMEA string. GPS NMEA data should be used to update android system GPS module. And other data will be parsed in our application.
How is this possible to achieve?
ATM: I parse all data from external device, but android GPS module does not receive NMEA strings. GPS must be handled by android system GPS module to update navigation software. This software uses just android GPS data, it does not support functions to pump in data from other applications.
Solution: I used mock locations. At the moment it is not possible to avoid GPS NMEA string parsing.
Code:
String mocLocationProvider = LocationManager.GPS_PROVIDER;
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
mLocationManager.addTestProvider(mocLocationProvider, false, false, false, false, true, true, false, Criteria.POWER_LOW, Criteria.ACCURACY_HIGH);
mLocationManager.setTestProviderEnabled(mocLocationProvider, true);
mLocationManager.setTestProviderStatus(mocLocationProvider, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
//update location
Location mCurrentLocation = new Location(mocLocationProvider);
mCurrentLocation.setLatitude(mGPSCurrLat);
mCurrentLocation.setLongitude(mGPSCurrLon);
mCurrentLocation.setAccuracy(1);
mCurrentLocation.setTime(mGPSCurrTimeUTC); //long getTime() from UTC string
mCurrentLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
mLocationManager.setTestProviderLocation(mocLocationProvider, mCurrentLocation);
Note: Enable "Allow mock locations" in android settings!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments