Create the layout
This section describes how to create the app layout.
Create the buttons and Textview
This app contains 13 buttons.
- ActivateAdminbtn – prompts the user to activate device administrator for the app.
- ActivateLicencebtn – activates the Knox KPE licence 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 – returns the default certificate alias, if there is one for the device.
- InstallCertificatebtn – installs the current certificate with user-provided details.
- DeleteCertificatebtn – deletes the Certificate with alias that matches 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/container is locked or user is not expected to enter password.
- RemovePackageExemptListbtn – removes the given package name from the exempt list.
- IsCCMPolicyEnabledForPackagebtn – checks if CCM policy is enabled for a given package.
- ToggleTimaKeystorebtn – enables/disables the TIMA Keystore.
- IsTimaKeystoreEnabledbtn – displays TIMA Keystore status (enabled/disabled).
Open activity_main.xml
and insert the following xml mark up.
This creates your screen layout.
NOTE – 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.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" /> <!-- CCM Profile Management--> <TextView android:id="@+id/ProfileManagementtxtview" android:layout_below="@id/ActivateLicensebtn" android:text="@string/ccm_profile_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/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>
You now see 13 buttons in a ScrollView. 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. These buttons are displayed in the screenshots below.
Create the Certificate_Alias_Input layout
In the layout folder which is present in res folder in Android view, create new Layout resource file and name it prompt_certificate_alias_to_delete.xml.
Open prompt_certificate_alias_to_delete.xml
and insert the following xml mark up. This creates your Certificate_Alias_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>
This creates the following EditText on the screen. The EditText is used to receive alias name of the certificate to be deleted.
Create the Certificate_Configuration layout
In the layout folder which is present in res folder in Android view, create new Layout resource file and name it prompt_certificate_alias_wifi_packages_csrresponse.xml.
Open prompt_certificate_alias_wifi_packages_csrresponse.xml file 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>
This creates the following CheckBoxes and EditText on the screen. The EditText is used to receive alias name of the certificate to be installed and the CheckBoxes are used for additional settings related to the certificate.
Create the Certificate_Path_And_Password layout
In the layout folder which is present in res folder in Android view, create new Layout resource file and name it prompt_certificate_path_and_password.xml
.
Open prompt_certificate_path_and_password.xml file and insert the following xml mark up. This creates 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>
This creates the following EditTexts on the screen. The EditTexts are used to receive current certificate’s path and password from the user.
Create the Package_Name_Input layout
In the layout folder which is present in res folder in Android view, create new Layout resource file and name it prompt_package_name.xml
.
Open prompt_package_name.xml file and insert the following xml mark up. This creates 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>
This creates the following EditText on the screen. The EditText is used to receive name of the package that is to be added to the exempt list or removed from the exempt list or to check whether the CCM policy is enabled for a given package.
For detailed information on creating Android layouts, see Google's page on how to Build a Simple User Interface.
Tutorial Progress
You are 2/7 done! Go to the next step.