Back to top

Create the layout

As of Knox 3.0, the preferred way to call Knox APIs is to upgrade an Android Work Profile to a Knox Workspace. This tutorial uses Android’s Device Manager to call Knox APIs. See Upgrade Android Work Profile to Knox Workspace for more information.

This section describes how to create the app layout.

Create the buttons and Textview

This app contains 5 buttons.

  • ActivateAdminbtn — prompts the user to activate device administrator for the app.
  • DeActivateAdminbtn — deactivates the device administrator for the app.
  • ActivateLicencebtn — activates the Knox KPE license key.
  • ToggleCamerabtn — Invokes a Knox SDK policy that enables or disables the camera.

Open activity_main.xml and insert the following xml mark up. This creates your screen layout.

To resolve the @string errors, copy these 2 files from the sample app into your project.

  • background.xml — KnoxSdkSample\app\src\main\res\drawable\Background
  • strings.xml — KnoxSdkSample\app\src\main\res\values\strings
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainpage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.samsung.knoxsdksample.MainActivity"> //update path to your own mainActivity

    <Button
        android:id="@+id/ActivateAdminbtn"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:text="@string/activate_admin"
        android:layout_below="@+id/logview_id"
        android:layout_centerHorizontal="true" />

    <Button
        android:id="@+id/DeactivateAdminbtn"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/ActivateAdminbtn"
        android:layout_below="@+id/ActivateAdminbtn"
        android:enabled="false"
        android:text="@string/deactivate_admin" />

    <Button
        android:id="@+id/ActivateLicencebtn"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/ActivateAdminbtn"
        android:layout_below="@+id/DeactivateAdminbtn"
        android:enabled="false"
        android:text="@string/activate_license" />

       <Button
        android:id="@+id/ToggleCamerabtn"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/GrantPermissionsbtn"
        android:enabled="false"
        android:layout_below="@+id/GrantPermissionsbtn"
        android:text="@string/toggle_camera" />

    <TextView
        android:id="@+id/logview_id"
        android:gravity="bottom"
        android:layout_width="320dp"
        android:layout_height="230dp"
        android:textColor="#3F51B5"
        android:background="@drawable/background"
        android:scrollbars="vertical"
        android:paddingLeft="10dp"
        android:layout_marginTop="22dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

You now see 5 buttons in the middle of the screen. ACTIVATE ADMIN, DEACTIVATE ADMIN, ACTIVATE LICENSEGRANT PERMISSIONS, and TOGGLE CAMERA. You will later assign methods to these buttons to control their respective actions. There is also a TextView at the top of the screen that will display any log messages.

Knox SDK Sample

For information on creating Android layouts, see Create your first Android app.

Tutorial progress

You are 4/10 done!

Next

Is this page helpful?