Skip to content

Commit b23bc0c

Browse files
committed
Added support for API 19 (Android 4.4) through API 30 (Android 11)
1 parent 8881344 commit b23bc0c

File tree

5 files changed

+77
-13
lines changed

5 files changed

+77
-13
lines changed

DeviceIdentifiersWrapper/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ apply plugin: 'com.android.library'
33
ext {
44
PUBLISH_GROUP_ID = 'com.zebra.deviceidentifierswrapper'
55
PUBLISH_ARTIFACT_ID = 'deviceidentifierswrapper'
6-
PUBLISH_VERSION = '0.1'
6+
PUBLISH_VERSION = '0.2'
77
}
88

99
android {
10-
compileSdkVersion 29
10+
compileSdkVersion 30
1111

1212
defaultConfig {
13-
minSdkVersion 26
13+
minSdkVersion 19
1414
targetSdkVersion 29
15-
versionCode 1
16-
versionName "0.1"
15+
versionCode 2
16+
versionName "0.2"
1717

1818
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1919

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.zebra.deviceidentifierswrapper">
3+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
4+
<queries>
5+
<package android:name="com.symbol.emdk.emdkservice" />
6+
</queries>
37
</manifest>

DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIHelper.java

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package com.zebra.deviceidentifierswrapper;
22

3+
import android.Manifest.permission;
4+
import android.annotation.SuppressLint;
35
import android.content.Context;
46
import android.content.pm.PackageInfo;
57
import android.content.pm.PackageManager;
68
import android.content.pm.Signature;
79
import android.database.Cursor;
810
import android.net.Uri;
911
import android.os.AsyncTask;
12+
import android.os.Build;
13+
import android.telephony.TelephonyManager;
1014
import android.util.Log;
1115

16+
import androidx.core.content.ContextCompat;
1217
import java.util.Base64;
1318

1419
public class DIHelper {
@@ -22,12 +27,67 @@ public class DIHelper {
2227
// This method will return the serial number in the string passed through the onSuccess method
2328
public static void getSerialNumber(Context context, IDIResultCallbacks callbackInterface)
2429
{
25-
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/oem.zebra.secure/build_serial"), callbackInterface);
30+
if (android.os.Build.VERSION.SDK_INT < 29) {
31+
returnSerialUsingAndroidAPIs(context, callbackInterface);
32+
} else {
33+
returnSerialUsingZebraAPIs(context, callbackInterface);
34+
}
35+
}
36+
37+
@SuppressLint({"MissingPermission", "ObsoleteSdkInt", "HardwareIds"})
38+
private static void returnSerialUsingAndroidAPIs(Context context, IDIResultCallbacks callbackInterface) {
39+
if (android.os.Build.VERSION.SDK_INT < 26) {
40+
callbackInterface.onSuccess(Build.SERIAL);
41+
} else {
42+
if (ContextCompat.checkSelfPermission(context, permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
43+
callbackInterface.onSuccess(Build.getSerial());
44+
} else {
45+
callbackInterface.onError("Please grant READ_PHONE_STATE permission");
46+
}
47+
}
48+
}
49+
50+
private static void returnSerialUsingZebraAPIs(Context context, IDIResultCallbacks callbackInterface) {
51+
new RetrieveOEMInfoTask()
52+
.execute(context, Uri.parse("content://oem_info/oem.zebra.secure/build_serial"),
53+
callbackInterface);
2654
}
2755

2856
// This method will return the imei number in the string passed through the onSuccess method
2957
public static void getIMEINumber(Context context, IDIResultCallbacks callbackInterface)
3058
{
31-
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/wan/imei"), callbackInterface);
59+
if (android.os.Build.VERSION.SDK_INT < 29) {
60+
returnImeiUsingAndroidAPIs(context, callbackInterface);
61+
} else {
62+
returnImeiUsingZebraAPIs(context, callbackInterface);
63+
}
64+
}
65+
66+
@SuppressLint({"MissingPermission", "ObsoleteSdkInt", "HardwareIds" })
67+
private static void returnImeiUsingAndroidAPIs(Context context, IDIResultCallbacks callbackInterface) {
68+
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
69+
if (android.os.Build.VERSION.SDK_INT < 26) {String imei = telephonyManager.getDeviceId();
70+
if (imei != null && !imei.isEmpty()) {
71+
callbackInterface.onSuccess(imei);
72+
} else {
73+
callbackInterface.onError("Could not get IMEI number");
74+
}
75+
} else {
76+
if (ContextCompat.checkSelfPermission(context, permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
77+
String imei = telephonyManager.getImei();
78+
if (imei != null && !imei.isEmpty()) {
79+
callbackInterface.onSuccess(imei);
80+
} else {
81+
callbackInterface.onError("Could not get IMEI number");
82+
}
83+
} else {
84+
callbackInterface.onError("Please grant READ_PHONE_STATE permission");
85+
}
86+
}
87+
}
88+
89+
private static void returnImeiUsingZebraAPIs(Context context, IDIResultCallbacks callbackInterface) {
90+
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/wan/imei"),
91+
callbackInterface);
3292
}
3393
}

SampleApplication/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 29
4+
compileSdkVersion 30
55

66
defaultConfig {
77
applicationId "com.zebra.emdk_deviceidentifiers_sample"
8-
minSdkVersion 29
8+
minSdkVersion 19
99
targetSdkVersion 29
10-
versionCode 1
11-
versionName "0.1"
10+
versionCode 2
11+
versionName "0.2"
1212

1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414
}
@@ -26,7 +26,7 @@ dependencies {
2626
implementation 'androidx.appcompat:appcompat:1.1.0'
2727
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
2828
implementation 'com.zebra.deviceidentifierswrapper:deviceidentifierswrapper:0.1'
29-
//implementation project(path: ':DeviceIdentifiersWrapper')
29+
// implementation project(path: ':DeviceIdentifiersWrapper')
3030
testImplementation 'junit:junit:4.12'
3131
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
3232
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<resources>
2-
<string name="app_name">Device ID for Android 10</string>
2+
<string name="app_name">Device ID for Android 4.4 -> 11</string>
33
</resources>

0 commit comments

Comments
 (0)