Blog

How to Implement Our Default UI Into Your Android Mobile App

By Kayla Klein / Jamie Lemon - Thursday, September 15, 2022

MuPDF App Kit, our mobile PDF SDK for Android, comes with a drop-in Default UI that enables easy PDF document viewing and editing for your applications. The Default UI connects with the native file browser on your Android platforms and accommodates for both tablet and phone layout. Let’s take a look at how easy it is to integrate with your own Android mobile application!  

(If you haven't already, you can download the MuPDF App Kit demo here.)

Jump to a section

 

Setup and Integration

 

You will need to use the Gradle build system to include MuPDF in your app. 

1. App Kit can be retrieved as pre-built artifacts from a local app/libs folder relative to your Android project. After downloading the latest version of MuPDF App Kit, copy the 5 aar files contained in mupdf-test/app/libs to your own app's app/libs/ folder. Sync your build.gradle and the App Kit libraries should be ready to go.
 

MuPDF App Kit pre-built artifacts in the mupdf-test/app/libs folder.

 

The MuPDF library requires Android version 6.0 or newer. 

2. Make sure that the minSdkVersion in your app's build.gradle is at least 23.


android {
    defaultConfig {
        minSdkVersion 23
        ...
    }
    ...
}

 

3. To add MuPDF App Kit to your project, reference the following dependencies in your Module  build.gradle


dependencies {
    ...
    // Dependency on view binding
    implementation 'androidx.databinding:viewbinding:7.1.2'
    // Dependency on navigation fragments
    implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
    // Dependency on local binaries
    implementation fileTree(dir: 'libs', include: ['*.aar'])
}

 

PDF documents in App Kit are always rendered inside of a document view instance.

4. Files that will need to instantiate and access the document view should reference the following:


import com.artifex.sonui.editor.DocumentView

 

Your Android Activity should handle the regular Android Activity Lifecycle events and inform any DocumentView instance of the corresponding Activity events. Additionally Activity interfaces are required to be set up for full App Kit functionality.

 

5. Include the Default UI activity in your AndroidManifest.xml as follows:


<activity android:name="com.artifex.sonui.editor.default_ui.DefaultUIActivity" android:exported="true" android:configchanges="orientation|keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|uiMode" android:screenorientation="fullSensor" android:theme="@style/sodk_editor_mui_theme">
</activity>

 

6. Import the Default UI activity into your application code:


import com.artifex.sonui.editor.default_ui.DefaultUIActivity

 

7. Instantiate and start the App Kit DefaultUIActivity with null data and it will automatically open the Android file browser for you to select a PDF file:


val defaultUI = Intent(this, DefaultUIActivity::class.java).apply {
    this.action = Intent.ACTION_VIEW
    this.data = null
}

startActivity(defaultUI)

 

MainActivity class in a sample Kotlin MuPDF App Kit project.
MainActivity class in a sample Kotlin MuPDF App Kit project.

 

And that’s it! The Default UI will handle the document interactions from here, allowing your Android app users to perform a variety of typical document actions against high fidelity PDFs.

MuPDF App Kit Default UI handling PDF document view and tapping Menu Options.
The Default UI - Menu Options

 

 

Typical Document Features and Actions

 

File Operations

There are a number of file operations available against a document - Save, Save As, Export, Print, Search.

PDF SDK Default UI for Print File Operations.

 

Annotations

The Default UI supports the creation of annotations on a PDF document, including:

Drawing

PDF SDK Default UI for Drawing Annotations.

 

Adding Notes

PDF SDK Default UI for Note Annotations.

 

Highlighting Text

PDF SDK Default UI for Highlight Annotations.

 

This blog post covered the Default UI included with our mobile PDF SDK for Android. To learn more about the full library of features, you can read the MuPDF App Kit documentation here.


More about MuPDF App Kit