diff options
author | Brad Leege <bleege@gmail.com> | 2016-07-18 17:23:32 -0500 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2016-07-18 17:59:07 -0500 |
commit | f5b5e6332b8391f93101f072b7595e36cbde4567 (patch) | |
tree | 9e2310167fad5a736380a49a3e4cdebde53880fd /platform/android/MapboxGLAndroidSDK/src/main/java/com | |
parent | 74fe96d2617f870206ff358d7dfcafccf4e109bc (diff) | |
download | qtlocation-mapboxgl-f5b5e6332b8391f93101f072b7595e36cbde4567.tar.gz |
[android] #5718 - Adding support for SharedPreferences
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com')
2 files changed, 13 insertions, 4 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java index 7936ab4d14..3993615eb9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java @@ -126,4 +126,6 @@ public class MapboxConstants { public static final String MAPBOX_SHARED_PREFERENCES_FILE = "MapboxSharedPreferences"; public static final String MAPBOX_SHARED_PREFERENCE_KEY_VENDORID = "mapboxVendorId"; public static final String MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_ENABLED = "mapboxTelemetryEnabled"; + public static final String MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_URL = "mapboxTelemetryStagingUrl"; + public static final String MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_ACCESS_TOKEN = "mapboxTelemetryStagingAccessToken"; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java index 1f1c583289..84df822ce9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java @@ -163,10 +163,12 @@ public class MapboxEventManager { ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); String stagingURL = appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_STAGING_SERVER); String stagingAccessToken = appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_STAGING_ACCESS_TOKEN); - String appName = context.getPackageManager().getApplicationLabel(appInfo).toString(); - PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); - String versionName = packageInfo.versionName; - int versionCode = packageInfo.versionCode; + + if (TextUtils.isEmpty(stagingURL) || TextUtils.isEmpty(stagingAccessToken)) { + Log.d(TAG, "Looking in SharedPreferences for Staging Credentials"); + stagingURL = prefs.getString(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_URL, null); + stagingAccessToken = prefs.getString(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_ACCESS_TOKEN, null); + } if (!TextUtils.isEmpty(stagingURL)) { eventsURL = stagingURL; @@ -176,6 +178,11 @@ public class MapboxEventManager { this.accessToken = stagingAccessToken; } + String appName = context.getPackageManager().getApplicationLabel(appInfo).toString(); + PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); + String versionName = packageInfo.versionName; + int versionCode = packageInfo.versionCode; + // Build User Agent if (TextUtils.equals(userAgent, BuildConfig.MAPBOX_EVENTS_USER_AGENT_BASE) && !TextUtils.isEmpty(appName) && !TextUtils.isEmpty(versionName)) { userAgent = appName + "/" + versionName + "/" + versionCode + " " + userAgent; |