Back to top

How to find a device’s IMEI and serial number with Knox Manage Open API

Last updated July 4th, 2023

Categories:

Environment

  • Knox Manage
  • Knox Manage Open API
  • Devices running Android 10 or higher
  • Corporate owned business only device or work profile on company-owned device

Overview

For devices running Android 10 and higher, all apps require the READ_PRIVILEGED_PHONE_STATE a privileged permission to access device identifiers. Third party apps are unable to declare this permission. With Knox Manage Open API, users are able to retrieve the device’s non-resettable identifiers (IMEI, serial number) if the device is enrolled in Knox Manage.

How to find a device’s IMEI and serial number with Knox Manage Open API

To find the IMEI or serial number:

  1. Access the Knox Manage Open API.
  2. Query the device information list with the Get Device List API.

The following is a sample implementation:

// Starting OkHttpClient
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create("grant_type=client_credentials&client_id=KM_Clinet_ID@yourtenant.testing&client_secret=Your_secret", mediaType);
Request request = new Request.Builder()
    .url("https://eu04.manage.samsungknox.com/emm/oauth/token") //depends on which server is assigned to your tenant
    .method("POST", body)
    .addHeader("Content-Type", "application/x-www-form-urlencoded")
    .build();

// This is response from Knox Manage servers as string
String stringResponse = "New String";
try {
    Response response = client.newCall(request).execute();
    //System.out.println(response.body().string());
    stringResponse = response.body().string();
    System.out.println("Token response from server: " + stringResponse);
} catch (IOException e) {
    System.out.println("An error occurred: " + e.getMessage());
}

// Extract the access token
String accessToken = stringResponse.substring(stringResponse.indexOf("{\"access_token\":\"") + "{\"access_token\":\"".length(), stringResponse.indexOf("\",\"token_type\":"));
// Print the access token
System.out.println("This is your token: " + accessToken);


// Request Body
RequestBody formBody = new FormBody.Builder()
    .add("userId", "UserID-logged-in-on-the-device")
    .build();

// Request
request = new Request.Builder()
    .url("https://eu04.manage.samsungknox.com/emm/oapi/device/selectDeviceList") //depends on which server is assigned to your tenant
    .addHeader("cache-control", "no-cache")
    .addHeader("content-type", "application/x-www-form-urlencoded")
    .addHeader("Authorization", "bearer " + accessToken)
    .post(formBody)
    .build();

// Response
try {
Response response = client.newCall(request).execute();
String responseBody = response.body().string();
System.out.println("This is response from server: " + responseBody);
} catch (IOException e) {
    // handle the exception
    System.out.println("An error occurred: " + e.getMessage());
}
}

Is this page helpful?