blob: 5f4f85ea7889e9c44ceee9da59c2136d99ea3101 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package com.mapbox.mapboxsdk.http;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.MapStrictMode;
import com.mapbox.mapboxsdk.Mapbox;
public class HttpIdentifier {
private HttpIdentifier() {
}
/**
* Returns the application identifier, consisting out the package name, version name and version code.
*
* @return the application identifier
*/
public static String getIdentifier() {
return getIdentifier(Mapbox.getApplicationContext());
}
/**
* Returns the application identifier, consisting out the package name, version name and version code.
*
* @param context the context used to retrieve the package manager from
* @return the application identifier
*/
private static String getIdentifier(@NonNull Context context) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
return String.format("%s/%s (%s)", context.getPackageName(), packageInfo.versionName, packageInfo.versionCode);
} catch (Exception exception) {
MapStrictMode.strictModeViolation(exception);
return "";
}
}
}
|