Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DeviceIdentifiersWrapper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'com.zebra.deviceidentifierswrapper'
PUBLISH_ARTIFACT_ID = 'deviceidentifierswrapper'
PUBLISH_VERSION = '0.1'
PUBLISH_VERSION = '0.2'
}

android {
compileSdkVersion 29
compileSdkVersion 30

defaultConfig {
minSdkVersion 26
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "0.1"
versionCode 2
versionName "0.2"

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

Expand Down
4 changes: 4 additions & 0 deletions DeviceIdentifiersWrapper/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zebra.deviceidentifierswrapper">
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<queries>
<package android:name="com.symbol.emdk.emdkservice" />
</queries>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.zebra.deviceidentifierswrapper;

import android.Manifest.permission;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.Log;

import androidx.core.content.ContextCompat;
import java.util.Base64;

public class DIHelper {
Expand All @@ -22,12 +27,67 @@ public class DIHelper {
// This method will return the serial number in the string passed through the onSuccess method
public static void getSerialNumber(Context context, IDIResultCallbacks callbackInterface)
{
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/oem.zebra.secure/build_serial"), callbackInterface);
if (android.os.Build.VERSION.SDK_INT < 29) {
returnSerialUsingAndroidAPIs(context, callbackInterface);
} else {
returnSerialUsingZebraAPIs(context, callbackInterface);
}
}

@SuppressLint({"MissingPermission", "ObsoleteSdkInt", "HardwareIds"})
private static void returnSerialUsingAndroidAPIs(Context context, IDIResultCallbacks callbackInterface) {
if (android.os.Build.VERSION.SDK_INT < 26) {
callbackInterface.onSuccess(Build.SERIAL);
} else {
if (ContextCompat.checkSelfPermission(context, permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
callbackInterface.onSuccess(Build.getSerial());
} else {
callbackInterface.onError("Please grant READ_PHONE_STATE permission");
}
}
}

private static void returnSerialUsingZebraAPIs(Context context, IDIResultCallbacks callbackInterface) {
new RetrieveOEMInfoTask()
.execute(context, Uri.parse("content://oem_info/oem.zebra.secure/build_serial"),
callbackInterface);
}

// This method will return the imei number in the string passed through the onSuccess method
public static void getIMEINumber(Context context, IDIResultCallbacks callbackInterface)
{
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/wan/imei"), callbackInterface);
if (android.os.Build.VERSION.SDK_INT < 29) {
returnImeiUsingAndroidAPIs(context, callbackInterface);
} else {
returnImeiUsingZebraAPIs(context, callbackInterface);
}
}

@SuppressLint({"MissingPermission", "ObsoleteSdkInt", "HardwareIds" })
private static void returnImeiUsingAndroidAPIs(Context context, IDIResultCallbacks callbackInterface) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (android.os.Build.VERSION.SDK_INT < 26) {String imei = telephonyManager.getDeviceId();
if (imei != null && !imei.isEmpty()) {
callbackInterface.onSuccess(imei);
} else {
callbackInterface.onError("Could not get IMEI number");
}
} else {
if (ContextCompat.checkSelfPermission(context, permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
String imei = telephonyManager.getImei();
if (imei != null && !imei.isEmpty()) {
callbackInterface.onSuccess(imei);
} else {
callbackInterface.onError("Could not get IMEI number");
}
} else {
callbackInterface.onError("Please grant READ_PHONE_STATE permission");
}
}
}

private static void returnImeiUsingZebraAPIs(Context context, IDIResultCallbacks callbackInterface) {
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/wan/imei"),
callbackInterface);
}
}
10 changes: 5 additions & 5 deletions SampleApplication/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
compileSdkVersion 30

defaultConfig {
applicationId "com.zebra.emdk_deviceidentifiers_sample"
minSdkVersion 29
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "0.1"
versionCode 2
versionName "0.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -26,7 +26,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.zebra.deviceidentifierswrapper:deviceidentifierswrapper:0.1'
//implementation project(path: ':DeviceIdentifiersWrapper')
// implementation project(path: ':DeviceIdentifiersWrapper')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
2 changes: 1 addition & 1 deletion SampleApplication/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">Device ID for Android 10</string>
<string name="app_name">Device ID for Android 4.4 -> 11</string>
</resources>