Android API Usage Demo sample app overview

A sample app called ApiUsageDemo demonstrates the supported way for a wrapped app to use various Android APIs. Ivanti has verified that when you wrap apps that use these APIs as demonstrated, the behavior of the wrapped app is functionally the same as the behavior of the unwrapped app.

Demonstrated APIs

The sample app ApiUsageDemo includes the following demonstrations:

IMPORTANT: Data loss protection policies on the server determine whether wrapped apps have access to the device’s camera and gallery. Be sure to allow access to the appropriate capability when testing the ApiUsageDemo app or your own wrapped app’s capabilities.

Audio Recorder Demo

The code uses MediaRecorder APIs and MediaPlayer APIs to record and playback audio media content.

Recording illustrates using the MediaRecorder setOutputFile() method with:

  • a file (absolute path)
  • a file descriptor from a RandomAccessFile

Wrapping the MediaPlayer APIs requires the android Internet permission, described in MediaPlayer and MediaMetaDataRetriever Internet permission requirement.

  • AudioRecorderDemoActivity.java
  • BaseRecorderDemoActivity.java

Capture Image Demo

This code uses FileProvider APIs to extract a file URI and pass it to the Camera app. The Camera app writes the captured image to that file. The demo app then uses the ImageView setImageURI API to display the photo.

Allow the Camera DLP on the server so that the app can access the camera to take a photo.

  • ImageCaptureDemoActivity.java

Documents Demo

This code demonstrates creating documents and opening folders and documents either inside or outside the AppConnect container. The code uses the intents ACTION_OPEN_DOCUMENT, ACTION_OPEN_DOCUMENT_TREE, and ACTION_CREATE_DOCUMENT. The code illustrates handling text, image, and videos.

Note the following:

  • Accessing files on a USB OTG drive requires a key-value pair on the AppConnect app configuration for Secure Apps Manager. See USB OTG support.

  • Allow the Gallery DLP on the server to select images from the device’s gallery.

  • To select an image from outside the AppConnect container, such as the device’s gallery, the app must be granted the permission Manifest.permission.READ_EXTERNAL_STORAGE. This permission is necessary because of how the wrapper implements selecting an image from outside the AppConnect container. For details, see Image selection from outside the AppConnect container.

  • Only Generation 2 wrapped apps support ACTION_CREATE_DOCUMENT on internal storage or external storage such as an SD drive.

  • Document/AbstractDocumentDemoActivity.java
  • Document/DocumentsDemoActivity.java
  • Document/DocumentTreeDemoActivity.java
  • Document/ImageDocumentDemoActivity.java
  • Document/TextDocumentDemoActivity.java
  • Document/VideoDocumentDemoActivity.java

Image Decoder Demo

APIUsageDemo displays the Image Decoder demo option only when running on Android 9.0. The code uses ImageDecoder APIs to read an image and display its bitmap. The images are included in the ApiUsageDemo app.

The demo illustrates using the ImageDecoder methods createSource(File file) and createSource(ContentResolver cr, Uri uri) to get the image from either a file or a URL. The demo then uses the ImageDecoder method decodeBitmap(ImageDecoder.source src) to get the bitmap.

  • ImageDecoderDemoActivity.java
  • ExtendedImageCapture.kt

Media Meta Data Retriever Demo

The code uses MediaMetadataRetriever APIs to extract the duration time of video content. Allow the Camera DLP on the server so that the app can access the camera to record the video.

Extracting the duration time illustrates using the MediaMetadataRetriever setDataSource() method with these data sources:

  • a file (absolute path)
  • a URI
  • a file descriptor from a ParcelFileDescriptor

Wrapping the MediaMetadataRetriever APIs requires the android Internet permission, described in MediaPlayer and MediaMetaDataRetriever Internet permission requirement..

  • MediaMetaDataRetrieverDemoActivity.java

Media Player Demo

The code uses MediaPlayer APIs to playback video media content. Allow the Camera DLP on the server so that the app can access the camera to record the video.

Playback illustrates using the MediaPlayer setDataSource() method to play back from these data sources:

  • a file (absolute path)
  • a URI
  • a file descriptor from a ParcelFileDescriptor
  • a file descriptor from a RandomAccessFile

Wrapping the MediaPlayer APIs requires the android Internet permission, described in MediaPlayer and MediaMetaDataRetriever Internet permission requirement.

  • MediaPlayerDemoActivity.java

Pick Image Demo

This code uses MediaStore APIs and the Glide library to select an image on the device from either inside or outside the AppConnect container. Allow the Gallery DLP on the server to pick an image from the device’s gallery.

To select an image from outside the AppConnect container, such as the device’s gallery, the app must be granted the permission Manifest.permission.READ_EXTERNAL_STORAGE. This permission is necessary because of how the wrapper implements selecting an image from outside the AppConnect container. For details, see Image selection from outside the AppConnect container.

  • PickImageDemoActivity.java

Share Content Demo

This code demonstrates sharing content such as text, images, and video, with other apps. The app can share content with non-AppConnect apps only if the key MI_AC_SHARE_CONTENT on the Secure Apps Manager’s AppConnect app configuration on Core has the value true.

  • ShareContentDemoActivity.java

“Sharing content from AppConnect for Android apps to non-AppConnect apps” in the AppConnect Guide for Core.

Video Recorder Demo

The code uses MediaRecorder APIs and MediaPlayer APIs to record and playback video media content.

Recording illustrates using the MediaRecorder setOutputFile() method with:

  • a file (absolute path)
  • a file descriptor from a RandomAccessFile

Wrapping the MediaPlayer APIs requires the android Internet permission, described in MediaPlayer and MediaMetaDataRetriever Internet permission requirement.

  • VideoRecorderDemoActivity.java
  • BaseRecorderDemoActivity.java