GPS: Remove NmeaListener workaround for Android 29 SDK

This commit is contained in:
Florin9doi 2024-01-07 02:17:01 +02:00
parent 134b3c17ba
commit bda9c99e79

View file

@ -13,8 +13,6 @@ import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
class LocationHelper implements LocationListener {
@ -27,8 +25,6 @@ class LocationHelper implements LocationListener {
private GpsStatus.NmeaListener mNmeaListener;
private float mAltitudeAboveSeaLevel = 0f;
private float mHdop = 0f;
private Method addNmeaListenerMethod = null;
private Method removeNmeaListenerMethod = null;
LocationHelper(Context context) {
mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
@ -74,17 +70,7 @@ class LocationHelper implements LocationListener {
onNmea(nmea);
}
};
// Use reflection to work around a bug in the Android 29 SDK.
// https://stackoverflow.com/questions/57975969/accessing-nmea-on-android-api-level-24-when-compiled-for-target-api-level-29
try {
if (addNmeaListenerMethod == null) {
addNmeaListenerMethod = LocationManager.class.getMethod("addNmeaListener", GpsStatus.NmeaListener.class);
}
addNmeaListenerMethod.invoke(mLocationManager, mNmeaListener);
} catch (Exception e) {
Log.w(TAG, "Couldn't get the nmea add method: " + e.toString());
}
mLocationManager.addNmeaListener(mNmeaListener);
}
mLocationEnable = true;
} catch (SecurityException e) {
@ -114,16 +100,7 @@ class LocationHelper implements LocationListener {
mGpsStatusListener = null;
}
if (mNmeaListener != null) {
// Use reflection to work around a bug in the Android 29 SDK.
// https://stackoverflow.com/questions/57975969/accessing-nmea-on-android-api-level-24-when-compiled-for-target-api-level-29
try {
if (removeNmeaListenerMethod == null) {
removeNmeaListenerMethod = LocationManager.class.getMethod("removeNmeaListener", GpsStatus.NmeaListener.class);
}
removeNmeaListenerMethod.invoke(mLocationManager, mNmeaListener);
} catch (Exception e) {
Log.w(TAG, "Couldn't get the nmea remove method: " + e.toString());
}
mLocationManager.removeNmeaListener(mNmeaListener);
mNmeaListener = null;
}
}