11package com .zebra .deviceidentifierswrapper ;
22
3+ import android .Manifest .permission ;
4+ import android .annotation .SuppressLint ;
35import android .content .Context ;
46import android .content .pm .PackageInfo ;
57import android .content .pm .PackageManager ;
68import android .content .pm .Signature ;
79import android .database .Cursor ;
810import android .net .Uri ;
911import android .os .AsyncTask ;
12+ import android .os .Build ;
13+ import android .telephony .TelephonyManager ;
1014import android .util .Log ;
1115
16+ import androidx .core .content .ContextCompat ;
1217import java .util .Base64 ;
1318
1419public 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}
0 commit comments