Back to top

This section describes how to create the app layout.

Create the buttons and Textview

This app contains a minimum of 10 buttons.

  • toggleAdminBtn — Prompts the user to activate device administrator for the app.
  • activateLicenseBtn — Activates the Knox KPE license key.
  • deactivateLicenseBtn — Deactivates the Knox KPE license key.
  • activateBackwardsCompatibleKeyBtn — Only appears for devices running a Knox version between 2.5 and 2.7.1.
  • showEnabledPackagesBtn — Shows a list of enabled apps in the TextView.
  • showDisabledPackagesBtn — Shows a list of disabled apps in the TextView.
  • enableAllDisabledPackagesBtn — Enables all disabled apps on the device.
  • enablePackageBtn — Prompts the user to type an app package name to enable.
  • disablePackageBtn — Prompts the user to type an app package name to disable.
  • toggleBatteryOptimizationWhitelistBtn — Prompts the user to type an app package name to add or remove from the battery optimization whitelist.
  • toggleForceStopBlacklistBtn — Prompts the user to type an app package name to add or remove from the force stop blocklist.

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 — app\src\main\res\drawable\Background
  • strings.xml — 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.appmanagement.MainActivity">

    <TextView
        android:id="@+id/logview_id"
        android:gravity="bottom"
        android:layout_width="320dp"
        android:layout_height="150dp"
        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="5dp"
        android:layout_below="@id/logview_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


            <Button
                android:id="@+id/toggleAdminBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:text="@string/activate_admin" />

            <Button
                android:id="@+id/activateLicenseBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_alignStart="@+id/toggleAdminBtn"
                android:layout_below="@+id/toggleAdminBtn"
                android:text="@string/activate_license" />

            <Button
                android:id="@+id/deactivateLicenseBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_alignStart="@+id/activateLicenseBtn"
                android:layout_below="@+id/activateLicenseBtn"
                android:text="@string/deactivate_license" />

            <Button
                android:id="@+id/activateBackwardsCompatibleKeyBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/deactivateLicenseBtn"
                android:layout_alignStart="@+id/deactivateLicenseBtn"
                android:text="Activate backwards compatible key"
                android:visibility="gone"/>

            <Button
                android:id="@+id/showEnabledPackagesBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/activateBackwardsCompatibleKeyBtn"
                android:layout_alignStart="@+id/activateBackwardsCompatibleKeyBtn"
                android:text="@string/show_enabled_apps"/>

            <Button
                android:id="@+id/showDisabledPackagesBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/showEnabledPackagesBtn"
                android:layout_alignStart="@+id/activateLicenseBtn"
                android:text="@string/show_disabled_apps"/>

            <Button
                android:id="@+id/enableAllDisabledPackagesBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/showDisabledPackagesBtn"
                android:layout_alignStart="@+id/activateLicenseBtn"
                android:text="@string/enable_all_disabled_apps"/>

            <Button
                android:id="@+id/enablePackageBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/enableAllDisabledPackagesBtn"
                android:layout_alignStart="@+id/activateLicenseBtn"
                android:text="@string/enable_given_app"/>

            <Button
                android:id="@+id/disablePackageBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/enablePackageBtn"
                android:layout_alignStart="@+id/activateLicenseBtn"
                android:text="@string/disable_given_app" />

            <Button
                android:id="@+id/toggleBatteryOptimizationWhitelistBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/disablePackageBtn"
                android:layout_alignStart="@+id/activateLicenseBtn"
                android:text="@string/toggle_battery_optimization_whitelist" />

            <Button
                android:id="@+id/toggleForceStopBlacklistBtn"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/toggleBatteryOptimizationWhitelistBtn"
                android:layout_alignStart="@+id/activateLicenseBtn"
                android:text="@string/toggle_force_stop_blacklist" />

       </RelativeLayout>
    </ScrollView>
</RelativeLayout>

Your device’s screen now shows 10 buttons (11 if your device is running a Knox version between 2.5 and 2.7.1):

  • ACTIVATE ADMIN
  • ACTIVATE LICENCE
  • DEACTIVATE LICENCE
  • SHOW ENABLED APPS
  • SHOW DISABLED APPS
  • ENABLE ALL DISABLED APPS
  • ENABLE GIVEN APP
  • DISABLE GIVEN APP
  • TOGGLE BATTERY WHITELIST
  • TOGGLE FORCE STOP BLACKLIST Later, you’ll assign methods to these buttons to control their respective actions. The TextView at the top of the screen displays log messages.

AppUI

AppUIWithBCK

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_user_package_name.xml.

Open the prompt_user_package_name.xml file. 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/prompt_user_package_name"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:paddingTop="20dp"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:paddingBottom="10dp"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/PackageNametxt"
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:text="@string/package_name" />


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

    </RelativeLayout>

</RelativeLayout>

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

Prompt

For detailed information on creating Android layouts, see Google’s documentation on how to Build a Simple User Interface.

Tutorial progress

You’ve completed 1 of 7 steps!

Next

Is this page helpful?