> 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/xamarin/guides/try-demo.md).

# Quick start: viewing a document in Xamarin.Android

Learn how to display a PDF in Xamarin.Android with this comprehensive guide. Find step-by-step instructions, SDK versions, permissions, and best practices for seamless integration. Optimize your app n

{% hint style="info" %}
**This tutorial only applies to Xamarin.Android.**
{% endhint %}

{% hint style="info" %}
**See Xamarin.iOS equivalent here .**
{% endhint %}

**Supporting Sdk versions:**

* Minimum: API 16 (Using Android Support Libraries)
* Recommended target: API 35

*This guide demonstrates how to display a PDF. To begin working with Apryse SDK, you must have first* [*added it to your project*](/xamarin/get-started/get-started.md)*, and* [*initialized the library*](/xamarin/get-started/faq/add-license.md)*.*

First make sure the following is in your `<application>` tag in `AndroidManifest.xml`.

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

```xml
<application ... android:largeHeap="true" android:usesCleartextTraffic="false">
    
    <activity android:name="com.pdftron.pdf.controls.DocumentActivity" android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize" android:windowSoftInputMode="adjustPan" android:theme="@style/PDFTronAppTheme"/>
</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 %}

Next, add permissions to `AndroidManifest.xml` file in the `<manifest>` tag (outside the `<application>` tag):

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

```xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
```

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

| Permission                       | Purpose                                                   |
| -------------------------------- | --------------------------------------------------------- |
| android.permission.INTERNET      | Internet permission for downloading online documents      |
| android.permission.RECORD\_AUDIO | Audio recording permission for creating sound annotations |

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

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

Add license key and activity declarations to `AndroidManifest.xml` file inside the `<application>` tag:

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

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

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

Finally, if you would like to customize the appearance of the viewer activity, define PDFTronAppTheme in `Resources/values/styles.xml`:

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

```xml
<resources>
    <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> <!-- Drawer --> <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> <!-- Action bar --> <item name="actionModeBackground">?attr/colorPrimary</item> <item name="windowActionModeOverlay">true</item> </style>
</resources>
```

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

{% hint style="info" %}
**If you are using your own theme, please don't forget to add/change the theme tag of your AndroidManifest file's corresponding activity declaration.**
{% endhint %}

To open a PDF file:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
// Open our sample document in the 'Resources/raw' resource folder
pdftron.PDF.Controls.DocumentActivity.OpenDocument(Resource.Raw.getting_started);
```

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

You will see:

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-40cf203f5e3307e449ca1586e8871ce3f05190d1%2Fa0205f1a4fbf82aac8134d8a8b7030f71614a3fb-1080x1920.png?alt=media)

Please note that changes for files opened from res will not be saved on disk.

To open your own file in DocumentActivity, use:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
// from internal storage
var localFile = Android.Net.Uri.FromFile(new Java.IO.File("myLocalFilePath"));
pdftron.PDF.Controls.DocumentActivity.OpenDocument(this, localFile);

// from content uri
var contentUri = Android.Net.Uri.Parse("myContentUri");
pdftron.PDF.Controls.DocumentActivity.OpenDocument(this, contentUri);

// from http/https
var fileLink = Android.Net.Uri.Parse("myFileLink");
pdftron.PDF.Controls.DocumentActivity.OpenDocument(this, fileLink);

// from res
pdftron.PDF.Controls.DocumentActivity.OpenDocument(this, Resource.Raw.my_file_res_id);
```

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


---

# 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/xamarin/guides/try-demo.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.
