> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/android/open-save-document/open/activity.md).

# Open documents using Activity with Apryse Android SDK

Learn how to open a document in an Activity using Apryse's Android SDK. View, annotate, sign, and edit PDFs with DocumentActivity. Follow Material design guidelines for a seamless experience. The Apry

Apryse's Android SDK ships with [`DocumentActivity`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/DocumentActivity.html), an all-in-one document reader and PDF editor. In addition to PDF files, it also supports [viewing other file formats](/android/ms-office/non-pdf.md) such as `.docx`, `.doc`, `.pptx`, `.xlsx`, `.md`, `.cbz` and various image formats. In this activity you can also read, annotate, sign, fill in PDF forms and more.

`DocumentActivity` extends Android's [`AppCompatActivity`](https://developer.android.com/reference/androidx/appcompat/app/AppCompatActivity/) and follows [Material design guidelines](https://material.io/guidelines/).

![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-ffa3eaa183402c0184a8845cef4ef7492205fd4b%2F1ed8a2fb5f4d6204964ec7788bb1094df6d78c7e-600x1200.gif?alt=media)

## Prerequisites

* [Integrated Apryse into your project](/android/get-started/get-started.md) and added the `com.pdftron:tools` package into your project.
* Minimum API: 21 (using AndroidX)
* Compile API: 35
* Recommended target API: 35

{% hint style="info" %}
**No trial license key required.**

The trial of Apryse Mobile SDK does not require a trial key. A commercial license key is required for use in a production environment. Please [contact sales](https://apryse.com/form/contact-sales) to purchase a commercial key or if you need any other license key assistance.
{% endhint %}

{% hint style="warning" %}
**Keep your license keys confidential.**

License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).
{% endhint %}

## Step 1: Update AndroidManifest.xml

1. In order to support all the features in `DocumentActivity`, we will need to add the Android permissions listed in [this table](/android/learn-more/permissions.md#android-permissions-list). However if you would like to disable certain features and customize your document viewer, you should leave out unnecessary permissions.

{% hint style="warning" %}
**Storage permission**

Please note that from Android 6.0 (API 23) and up, applications need to request storage permission at runtime before accessing any files on device.
{% endhint %}

1. Enable `largeHeap` and set `android:name` in the `<application>` tag to MultiDexApplication:

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<!-- Include existing attributes in application -->
<application android:name="androidx.multidex.MultiDexApplication" android:largeHeap="true" android:usesCleartextTraffic="false">
</application>
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**If your app is targeting Android SDK version 28 or higher, you will need to add the android:usesCleartextTraffic="true" attribute in your application tag to open HTTP files in the viewer. If you are only working with HTTPS files, this is not required.**
{% endhint %}

1. If you have not done so already, add the `<meta-data>` tag containing a reference to your license key in the `AndroidManifest.xml` file. Also, declare `DocumentActivity` in the same file. The final `AndroidManifest.xml` file should look something like this:

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Include existing attributes in application -->
<manifest>
    <!-- Required permissions are added here -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <!-- Add multidex support, enable largeHeap -->
    <!-- Include existing attributes in application -->
    <application android:name="androidx.multidex.MultiDexApplication" android:largeHeap="true" android:usesCleartextTraffic="false">    

        <!-- Add license key in meta-data tag here. This should be inside the application tag. -->
        <meta-data android:name="pdftron_license_key" android:value="${pdftronLicenseKey}"/>
            
        <!-- Document viewer activity declaration-->
        <activity android:name="com.pdftron.pdf.controls.DocumentActivity" android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize" android:windowSoftInputMode="adjustPan" android:theme="@style/PDFTronAppTheme"/>
    </application>
</manifest>
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Step 2: Launch the viewer

Launch `DocumentActivity` by specifiying a local file path, an HTTP/HTTPS url, or a Content Uri:

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
import android.net.Uri;
import java.io.File;
import com.pdftron.pdf.controls.DocumentActivity;

// Set the cache location using the config to store the cache file
ViewerConfig config = new ViewerConfig.Builder().openUrlCachePath(this.getCacheDir().getAbsolutePath()).build();

// from internal storage
final Uri uri = Uri.fromFile(new File("myLocalFilePath"));
// from content uri
final Uri uri = Uri.parse("myContentUri");
// from http/https
final Uri uri = Uri.parse("myFileLink");
// from assets
final Uri uri = Uri.parse("file:///android_asset/my_file.pdf");

// intent builder
Intent intent = DocumentActivity.IntentBuilder.fromActivityClass(this, DocumentActivity.class)
        .withUri(uri)
        .usingConfig(config)
        .usingTheme(R.style.PDFTronAppTheme)
        .build();
startActivity(intent);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
import android.net.Uri
import java.io.File
import com.pdftron.pdf.controls.DocumentActivity

// Set the cache location using the config to store the cache file
val config = ViewerConfig.Builder().openUrlCachePath(this.getCacheDir().getAbsolutePath()).build();

// from internal storage
val uri = Uri.fromFile(new File("myLocalFilePath"))
// from content uri
val uri = Uri.parse("myContentUri")
// from http/https
val uri = Uri.parse("myFileLink")
// from assets
val uri = Uri.parse("file:///android_asset/my_file.pdf")

// intent builder
val intent: Intent = DocumentActivity.IntentBuilder.fromActivityClass(this, DocumentActivity::class.java)
        .withUri(uri)
        .usingConfig(config)
        .usingTheme(R.style.PDFTronAppTheme)
        .build()
startActivity(intent)
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Step 3: (Optional) Customize the viewer

* If you would like to customize the appearance of the viewer activity, define `PDFTronAppTheme` in `res/values/styles.xml`:You can learn more about this in the [customize the viewer's theme guide ](/android/ui-customization/custom-theme-a.md).

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<style name="PDFTronAppTheme" parent="PDFTronAppThemeBase"> <item name="colorPrimary">@color/app_color_primary_day</item> <item name="colorPrimaryDark">@color/app_color_primary_dark_day</item> <item name="colorAccent">@color/app_color_accent</item> <!-- Action bar --> <item name="actionModeBackground">?attr/colorPrimary</item> <item name="windowActionModeOverlay">true</item> </style>
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
`DocumentActivity` uses the `AppCompat` theme for material colors. Make sure that the value of `android:theme` in your `activity` tag also extends the `AppCompat` theme.
{% endhint %}

* Also, if you would like to customize the UI components in `DocumentActivity`, you can use [`ViewerConfig.Builder`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/config/ViewerConfig.Builder.html). For example:For details on customizing the UI and using `ViewerConfig.Builder`, check out the [configuration tutorial ](/android/viewer/fragment-config.md).

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
import com.pdftron.pdf.config.ViewerConfig;

ViewerConfig.Builder builder = new ViewerConfig.Builder();
ViewerConfig config = builder
    .fullscreenModeEnabled(true)
    .multiTabEnabled(true)
    .documentEditingEnabled(true)
    .longPressQuickMenuEnabled(true)
    .toolbarTitle("Simple Reader")
    .showSearchView(true)
    .build();
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
import com.pdftron.pdf.config.ViewerConfig

val builder = ViewerConfig.Builder()
val config = builder
  .fullscreenModeEnabled(true)
  .multiTabEnabled(true)
  .documentEditingEnabled(true)
  .longPressQuickMenuEnabled(true)
  .toolbarTitle("Simple Reader")
  .showSearchView(true)
  .build()
```

{% endcode %}
{% endtab %}
{% endtabs %}

Check out the [diagram of the overall view hierarchy](/android/viewer/viewer-overview.md) for more.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/android/open-save-document/open/activity.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
