> 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/get-started/viewdoc.md).

# How to view document in Android with DocumentActivity

Here is a guide explainging how to view a document with DocumentActivity in Android using Kotlin and Java

This section will show you how to open a document in a [`DocumentActivity`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/DocumentActivity.html). This is an AppCompatActivity which contains a [`PdfViewCtrlTabHostFragment2`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/PdfViewCtrlTabHostFragment2.html) and packages all the standard features used during document viewing. You can learn more in our [document viewer overview](/android/viewer/viewer-overview.md).

1. The `AndroidManifest.xml` file needs to be updated to request permissions to allow `DocumentActivity` to function properly. You also need to add some attributes to the `<application>` tag as well as a new `<activity>` tag to define the `DocumentActivity`. For more, see [detailed description of permission requirements](/android/learn-more/permissions.md#android-permissions-list).

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

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

    <!-- Add multidex support and enable largeHeap. Also enable usesCleartextTraffic in application attributes if you are working with HTTP files. If you are only working with HTTPS files, this is not required. -->
    <!-- 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. -->
        <!-- This is from the Integration stage-->
        <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 %}

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

Please follow the latest [Android best practices and guidelines](https://developer.android.com/training/permissions/usage-notes/).
{% endhint %}

{% hint style="warning" %}
**Warn**

If your app targets Android SDK version 28 or higher, add the `android:usesCleartextTraffic="true"` attribute in your application tag to open HTTP files in the viewer. If you're only working with HTTPS files, this is not required.
{% endhint %}

2. Import the following in your MainActivity.java file.

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

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

{% endcode %}
{% endtab %}

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

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

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

3. Inside the `onCreate` method for your `MainActivity` class, add the following lines to open a demo PDF from a URL. You can open documents using `DocumentActivity` in many ways.

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

```java
ViewerConfig config = new ViewerConfig.Builder().openUrlCachePath(this.getCacheDir().getAbsolutePath()).build();
final Uri fileLink = Uri.parse("https://pdftron.s3.amazonaws.com/downloads/pl/PDFTRON_mobile_about.pdf");
DocumentActivity.openDocument(this, fileLink, config);
```

{% endcode %}
{% endtab %}

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

```kotlin
val config = ViewerConfig.Builder().openUrlCachePath(this.getCacheDir().getAbsolutePath()).build();
val fileLink = Uri.parse("https://pdftron.s3.amazonaws.com/downloads/pl/PDFTRON_mobile_about.pdf")
DocumentActivity.openDocument(this, fileLink, config)
```

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

{% hint style="info" %}
**DocumentActivity has limited runtime customizability.**

If you require more customizability options, please use `PdfViewCtrlTabHostFragment2` since it gives you full control over UI and behavior customization. Read more on the different components in the [viewer overview guide for Andriod ](/android/viewer/viewer-overview.md).
{% endhint %}

Your app should look something like this:

![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-bb206ec1d18fef0a46a819fd87a140a1ed6371a5%2F199cca72d0118cdfa361d3debf9f21777836b2f3-1080x2160.png?alt=media)

You can explore the features of the viewer and also many [customization options](/android/get-started/customize-a.md).

### More loading options

`DocumentActivity` can open documents from various resources including internal storage, URIs, web servers and the application's `res` folder.

You can open files from the these sources using the code below:

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

```java
import android.net.Uri;
import java.io.File;
import com.pdftron.pdf.config.ViewerConfig;
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.config.ViewerConfig
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 %}

{% hint style="info" %}
**A cache location is preferred when loading contents from web servers.**

If you did not request Storage permission, the app sandbox is recommended for cache path, otherwise you have control over where you would like to store the cache file.
{% endhint %}

## Next step

<a href="/android/get-started/customize-a.md" class="button primary">Customize</a>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/android/get-started/viewdoc.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
