Back to top

This section describes how to create the app layout.

Create the buttons and Textview

This app contains 14 buttons.

  • ActivateAdminbtn — Prompts the user to activate device administrator for the app.
  • ActivateLicencebtn — Activates the Knox KPE license key.
  • DeactivateLicenseBtn — Deactivates the Knox KPE license key.
  • SetCCMProfilebtn — Applies the CCM profile created by the user through the dialog box.
  • GetCCMProfilebtn — Displays the current CCM profile set through SetCCMProfilebtn.
  • DeleteCCMProfilebtn — Deletes the current CCM profile set through SetCCMProfilebtn.
  • GetDefaultCertAliasbtn — If it exists, returns the default certificate alias.
  • InstallCertificatebtn — Installs the current certificate with user-provided details.
  • DeleteCertificatebtn — Deletes the certificate with an alias that matches the user-provided details.
  • AddPackageExemptListbtn — Adds the given package name to the exempt list. This is required in case an app (running in background) needs access to certificates when the device or container is locked, or the user is not expected to enter a password.
  • RemovePackageExemptListbtn — Removes the given package name from the exempt list.
  • IsCCMPolicyEnabledForPackagebtn — Checks if a CCM policy is enabled for a given package.
  • ToggleTimaKeystorebtn — Enables or disables the TIMA Keystore.
  • IsTimaKeystoreEnabledbtn — Displays the TIMA Keystore status (enabled or disabled).

Open activity_main.xml and insert the following XML mark up to create your screen layout.

To resolve the @string errors, copy the below 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.knox.example.ccm.MainActivity">

    <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:paddingStart="10dp"
        android:paddingEnd="10dp"
        android:layout_marginTop="22dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_marginTop="10dp"
        android:layout_below="@id/logview_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <RelativeLayout
        android:padding="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/ToggleAdminbtn"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:text="@string/toggle_admin"
            android:layout_centerHorizontal="true" />

        <Button
            android:id="@+id/ActivateLicensebtn"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/ToggleAdminbtn"
            android:layout_below="@+id/ToggleAdminbtn"
            android:text="@string/activate_klm" />
        
        <Button
            android:id="@+id/DeactivateLicensebtn"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/ActivateLicensebtn"
            android:layout_below="@+id/ActivateLicensebtn"
            android:text="@string/activate_klm" />

        <!-- CCM Profile Management-->
        <TextView
            android:id="@+id/ProfileManagementtxtview"
            android:layout_below="@id/DeactivateLicensebtn"
            android:text="@string/ccm_profile_management"
            android:layout_marginTop="5dp"
            android:textColor="@color/colorPrimary"
            android:layout_alignStart="@id/DeactivateLicensebtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <RelativeLayout
            android:id="@+id/ProfileManagementlrl"
            android:layout_centerHorizontal="true"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/ProfileManagementtxtview"
            android:background="@drawable/button_container">

            <Button
                android:id="@+id/SetCCMProfilebtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:text="@string/set_ccm_profile"/>

            <Button
                android:id="@+id/GetCCMProfilebtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/SetCCMProfilebtn"
                android:text="@string/get_ccm_profile"/>

            <Button
                android:id="@+id/DeleteCCMProfilebtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/GetCCMProfilebtn"
                android:text="@string/delete_ccm_profile"/>
        </RelativeLayout>

        <!-- CCM Certificate Management -->
        <TextView
            android:id="@+id/CertificateManagementtxtview"
            android:layout_below="@id/ProfileManagementlrl"
            android:text="@string/ccm_certificate_management"
            android:layout_marginTop="5dp"
            android:textColor="@color/colorPrimary"
            android:layout_alignStart="@id/ActivateLicensebtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <RelativeLayout
            android:id="@+id/CertificateManagementrl"
            android:layout_centerHorizontal="true"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/CertificateManagementtxtview"
            android:background="@drawable/button_container">

            <Button
                android:id="@+id/GetDefaultCertAliasbtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:text="@string/get_default_cert_alias"/>

            <Button
                android:id="@+id/InstallCertificatebtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/GetDefaultCertAliasbtn"
                android:text="@string/install_certificate"/>

            <Button
                android:id="@+id/DeleteCertificatebtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/InstallCertificatebtn"
                android:text="@string/delete_certificate"/>
        </RelativeLayout>

        <!-- CCM Package Exemption -->
        <TextView
            android:id="@+id/PackageExemptiontextview"
            android:layout_below="@id/CertificateManagementrl"
            android:text="@string/ccm_package_management"
            android:layout_marginTop="5dp"
            android:textColor="@color/colorPrimary"
            android:layout_alignStart="@id/ActivateLicensebtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <RelativeLayout
            android:id="@+id/PackageExemptionrl"
            android:layout_centerHorizontal="true"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/PackageExemptiontextview"
            android:background="@drawable/button_container">

            <Button
                android:id="@+id/AddPackageExemptListbtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:text="@string/add_package_to_exempt_list"/>

            <Button
                android:id="@+id/RemovePackageExemptListbtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/AddPackageExemptListbtn"
                android:text="@string/remove_package_from_exempt_list"/>

            <Button
                android:id="@+id/IsCCMPolicyEnabledForPackagebtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/RemovePackageExemptListbtn"
                android:text="@string/check_ccm_policy_enabled_for_package"/>
        </RelativeLayout>

        <!-- TIMA Keystore -->
        <TextView
            android:id="@+id/TIMAKeystoretextview"
            android:layout_below="@id/PackageExemptionrl"
            android:text="@string/tima_keystore"
            android:layout_marginTop="5dp"
            android:textColor="@color/colorPrimary"
            android:layout_alignStart="@id/ActivateLicensebtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <RelativeLayout
            android:id="@+id/TIMAKeystorerl"
            android:layout_centerHorizontal="true"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/TIMAKeystoretextview"
            android:background="@drawable/button_container">
            <Button
                android:id="@+id/ToggleTimaKeystorebtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:text="@string/toggle_tima_keystore"/>

            <Button
                android:id="@+id/IsTimaKeystoreEnabledbtn"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ToggleTimaKeystorebtn"
                android:text="@string/is_tima_keystore_enabled"/>
            </RelativeLayout>
        </RelativeLayout>
    </ScrollView>
</RelativeLayout>

The button to activate the backwards compatibility key only appears if the device’s Knox version between is between 2.5 and 2.7.1, or Knox API 17 to 21. Depending on your Knox version, 13 or 14 buttons are displayed in a ScrollView. You can later assign methods to these buttons to control their respective actions. At the top of the screen, a TextView displays log messages. These buttons are displayed in the screenshots below.

ccmUI

ccmUIwithBCK

Create the Certificate_Alias_Input layout

In the Android view, navigate to the res folder, then to the Layout folder. Create a new Layout resource file and name it prompt_certificate_alias_to_delete.xml.

Open prompt_certificate_alias_to_delete.xml. Then, insert the following XML mark up to create your Package_Name_Input layout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/delete_cert_group"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    android:paddingLeft="25dp"
    android:paddingRight="25dp"
    android:paddingTop="20dp">

    <TextView
        android:id="@+id/dtxtCertificateAlias"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/certificate_alias"
        android:textColor="@android:color/black" />

    <EditText
        android:id="@+id/edtxtCertificateAlias"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/dtxtCertificateAlias"
        android:hint="@string/certificate_alias_hint" />
</RelativeLayout>

The EditText shown below is used to receive package name inputs from the user.

deleteCertificatePopup

Create the Certificate_Configuration layout

In the Android view, navigate to the res folder, then to the Layout folder. Create a new Layout resource file and name it prompt_certificate_alias_wifi_packages_csrresponse.xml.

Open prompt_certificate_alias_wifi_packages_csrresponse.xml and insert the following XML mark up. This creates your Certificate_Configuration layout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="20dp"
    android:paddingLeft="25dp"
    android:paddingRight="25dp"
    android:paddingBottom="10dp"
    android:id="@+id/configure_certificate_group"
    android:layout_width="match_parent" android:layout_height="wrap_content">

        <TextView
            android:id="@+id/dtxtCertificateAlias"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/certificate_alias"
            android:textColor="@android:color/black" />
        <EditText
            android:id="@+id/edtxtCertificateAlias"
            android:hint="@string/certificate_alias_hint"
            android:layout_below="@id/dtxtCertificateAlias"
            android:layout_width="250dp"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/chkAllowAllPackages"
            android:layout_below="@id/edtxtCertificateAlias"
            android:text="@string/allow_all_packages"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/chkAllowWifi"
            android:layout_below="@id/chkAllowAllPackages"
            android:text="@string/allow_wifi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/chkIsCSRResponse"
            android:layout_below="@id/chkAllowWifi"
            android:text="@string/enable_iscsrresponse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
</RelativeLayout>

The CheckBoxes and EditText shown below are created. The EditText is used to receive the alias name of the certificate to be installed, and the CheckBoxes are used for additional settings related to the certificate.

configureCertificatePopup

Create the Certificate_Path_And_Password layout

In the Android view, navigate to the res folder, then to the Layout folder. Create a new Layout resource file and name it prompt_certificate_path_and_password.xml.

Open prompt_certificate_path_and_password.xml. Then, insert the following XML mark up to create your Certificate_Path_And_Password layout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="20dp"
    android:paddingLeft="25dp"
    android:paddingRight="25dp"
    android:paddingBottom="10dp"
    android:id="@+id/certificate_pass_and_path_group"
    android:layout_width="match_parent" android:layout_height="wrap_content">

    <TextView
        android:id="@+id/dtxtCertificatePath"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/certificate_path"
        android:textColor="@android:color/black" />
    <EditText
        android:id="@+id/edTxtCertificatePath"
        android:text="@string/path_hint"
        android:layout_below="@id/dtxtCertificatePath"
        android:layout_width="250dp"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/dtxtCertificatePassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/edTxtCertificatePath"
        android:text="@string/certificate_password"
        android:textColor="@android:color/black" />
    <EditText
        android:id="@+id/edTxtCertificatePassword"
        android:inputType="textPassword"
        android:layout_below="@id/dtxtCertificatePassword"
        android:layout_width="250dp"
        android:layout_height="wrap_content" />

</RelativeLayout>

The EditTexts shown below are created, which are used to receive the current certificate’s path and password from the user.

setCertPopup

Create the Package_Name_Input layout

In the Android view, navigate to the res folder, then to the Layout folder. Create a new Layout resource file and name it prompt_package_name.xml.

Open prompt_package_name.xml, Then, insert the following XML mark up to create your Package_Name_Input layout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/package_name_input_group"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    android:paddingLeft="25dp"
    android:paddingRight="25dp"
    android:paddingTop="20dp">

    <TextView
        android:id="@+id/dtxtPackageName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/package_name"
        android:textColor="@android:color/black" />

    <EditText
        android:id="@+id/edTxtPackageName"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/dtxtPackageName"
        android:hint="@string/package_name_hint" />
</RelativeLayout>

The EditText shown below is created, which is used to receive the name of the package to be added or removed from the exempt list. It can also check whether the CCM policy is enabled for a given package.

addPackagePopup

removePackagePopup

isCCMPolicyEnabledPopup

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

Tutorial progress

You’ve completed 1 of 7 steps!

Next

Is this page helpful?