Back to top

Manage devices using ISV APIs

As described in Independent Software Vendors, Knox 3.7.1 introduces APIs designed for ISVs as they no longer need Device Admin permission or a Knox license.

This tutorial describes how ISVs can use these new APIs to configure a mobile device. For more comprehensive detail, see the following:

  • com.samsung.android.knox.ex : for the syntax of and sample code for all available API classes, constants, and methods
  • Sample app: for complete sample app code showing the end-to-end UI setup and control of a device

This tutorial uses Java naming conventions. Constants are in all caps (PARAM_PACKAGE_BATTERY_OPTIMIZATION_ALLOW_LIST), classes have initial capitalization (ContentValues), and methods are in camel case (getConstantResolver). To see if an API is from the Android or Samsung Knox SDK, hover over the linked text to see if it goes to an Android or Samsung web domain.

Knox 3.7.1 introduced the use of Android content providers to manage features. For more information, browse Use content providers. The rest of this tutorial shows how to use content providers to manage a device, settings, and apps.

Map hardware key to app

Use the following to identify the hardware key and the app to launch:

Item Description
Uri content://com.samsung.android.knox.sdk/config/settings
key key-code
key component-name

Here are key-code values for hardware buttons on a device:

  • Volume up: 24
  • Volume down: 25
  • Power (side): 26
  • Push-to-talk (XCover): 1015
  • Top (Emergency, XCover): 1079

Use a URI to identify the data being managed, instantiate a ContentValues object, identify the hardware key to press, and the app to launch.

Uri uri = Uri.parse("content://com.samsung.android.knox.sdk/config/settings");
ContentValues contentValues = new ContentValues();
contentValues.put("component-name", "com.android.settings/com.android.settings.Settings");
contentValues.put("event", "long-press");
contentValues.put("key-code", "24");
contentValues.put("action", "activity");
String selection = "key=?";
String[] selectionArgs = new String[] {"hardware-key"};
mContext.getContentResolver().update(uri, contentValues, selection, selectionArgs);

Set screen timeout period

To set the time duration before a screen goes into sleep mode, use the following:

Item Description
Uri content://com.samsung.android.knox.sdk/config/device
key screen-timeout
value 60

Use a URI to identify the data being managed, instantiate a ContentValues object, identify the screen timeout setting, and set it to 60 seconds.

Uri uri = Uri.parse("content://com.samsung.android.knox.sdk/config/device");
ContentValues contentValues = new ContentValues();
contentValues.put("screen-timeout", "30");
String selection = "key=?";
String[] selectionArgs = new String[] {"screen-timeout"};
mContext.getContentResolver().update(uri, contentValues, selection, selectionArgs);

Enable app for battery optimization

To set up an app for battery optimization, use the following:

Item Description
Uri content://com.samsung.android.knox.sdk/config/application
key package-battery-optimization-allow-list
key com.android.settings (the Android Settings app)

To add an app for battery optimization, use a URI to identify the data being managed, instantiate a ContentValues object, add a battery optimization app to be stored in a ContentProvider.

Uri uri = Uri.parse("content://com.samsung.android.knox.sdk/config/application");
ContentValues contentValues = new ContentValues();
contentValues.put("package-battery-optimization-allow-list", "com.android.settings");
String selection = "key=?";
String[] selectionArgs = new String[] {"package-battery-optimization-allow-list"};
mContext.getContentResolver().update(uri, contentValues, selection, selectionArgs);

To get the current list of apps in the battery optimization list:

    Uri uri = Uri.parse("content://com.samsung.android.knox.sdk/config/application");
    String selection = "key=?";
    String[] selectionArgs = new String[] {"package-battery-optimization-allow-list"};
    Cursor cursor = mContext.getContentResolver().query(uri, null, selection, selectionArgs, null);
    ArrayList allowList = new ArrayList<>();
    if (cursor != null) {
        cursor.moveToFirst();
        do {
            allowList.add(cursor.getString(0));
        } while (cursor.moveToNext());
    }

To delete an app from the battery optimization list, use a URI to identify the data being managed, select the app to delete from the battery optimization list, and delete it.

Uri uri = Uri.parse("content://com.samsung.android.knox.sdk/config/application");
String selection = "key=? AND package-name=?";
String[] selectionArgs = new String[] {"package-battery-optimization-allow-list", "com.android.settings"};
mContext.getContentResolver().delete(uri, selection, selectionArgs);

Is this page helpful?