Menu

Use content providers

Knox 3.7.1 introduced the use of Android content providers for managing devices and peripherals, using Android methods to configure Knox settings stored as key-value pairs. This is in contrast to past Knox releases, which used custom Knox methods to manage each atomic Knox setting. 

Here is how you configure a device setting (turn on NFC) in Knox 3.7.1:

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

To compare, here is how you configure the same setting in earlier Knox releases:

EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
NFcPolicy nfcPolicy = edm.getNfcPolicy();
boolean result = nfcPolicy.startNFC(true);

If you're new to Android content providers, familiarize yourself with the following concepts, which are used in the tutorials and sample app:

Item Description
content provider Stores, secures, and controls shared access to data.
content URI Identifies data in a content provider.
getContentResolver Gets an instance of the ContentResolver to access the content.
update, query, delete Sets, gets, and deletes data in the content provider.
ContentValues Stores values that ContentResolver can process.
put Adds key-value pairs to a data set.

Next, see the tutorials that walk through how to use content providers with the new Knox ISV APIs:

Or, if you're already comfortable with content providers, dive into the sample app.

Share it: