Android Widgets in the Enterprise

main pic

Written by:  Andrew Frolkin

Android Secure Workspace (SWS) for BlackBerry Enterprise Service enables Android devices to be managed by BES12 with enhanced security for enterprise applications. SWS separates your Android device into two perimeters, the personal and work spaces. In addition to the secure enterprise applications included in secure workspace, administrators can easily wrap and deploy internal apps onto the secure workspace.

Developing applications specifically for the workspace requires little to no custom development and the traditional Android features you are used to are Integrated into SWS.

We’ll be looking at a sample application that demonstrates this integration. We’ll go through the process of developing a simple home screen widget with no launchable activity. Clicking on the widget will trigger the work email application to open a new compose window.

Secure workspace supports Android app widgets in exactly the way you expect app widgets to work in the personal perimeter. Much like a traditional Android Widget, the user will need to first add the widget to the home screen from the widget menu.

Creating an Email Widget

Step 1. In your IDE of choice, create a new Android project. If the project generated a main activity, delete the activity since we don’t need one for this widget.

Step 2. Setup the Android manifest for the widget. We need to register a broadcast receiver to allow the widget to launch an email compose app activity. To see more information about component, see the official Android documentation on App Widgets.

code 1


Step 3. In the previous step we declared a widget provider, this step will define the configuration for that provider. Create a new file res/xml/widget_provider.xml . Since this widget has no need to refresh automatically (you would want to refresh periodically if the widget displayed dynamic content like a twitter feed) we will set the update period to 0. We also need to set a main layout for the widget which we will create in the next step.

code 2


Step 4. Create the layout file for the widget in res/layout/widget_main.xml. For this app, we just want to show a simple button with the text “Open Email”.

code 3


Step 5. Finally, to begin the email intent when clicking on the button, we need to add some logic to the provider class. Create a new class that extends AppWidgetProvider in java/com.afrolkin.emailwidget/ and start the intent to open an email application.  In this case, we need to attach a click listener to the button which starts a pending ACTION_SENDTO intent. We also need to pass a URI to the intent to specify the information we want to show in the email compose window.

code 4


Step 6. Run the app to make sure there are no errors, and deploy it to the device through SWS.


Once deployed to the device, there won’t be a launchable app in the app drawer since we haven’t defined a launchable activity. To view the widget, bring up the widget menu in your launcher and add the widget to a home screen.

If we deploy this app to an Android device without wrapping it through SWS, clicking the widget will bring up an intent chooser which will prompt the user to select an application to handle the intent (in this case, the user will have to select from a list of email applications installed on the device).



After wrapping and deploying the app to SWS, clicking on the widget will only bring up the work space email application. The user will also be unable to add the widget in their personal space.

The source code for this sample is available here.


About BlackBerry

BlackBerry is an enterprise software and services company focused on securing and managing IoT endpoints.