Quick start - view a document in Android
Prerequisites
Minimum API: 21 (using AndroidX)
Compile API: 35
Recommended target API: 35
The latest version of Android Studio.
If your app is using AndroidX you will also need to add
android.useAndroidX=trueandandroid.enableJetifier=truein yourgradle.propertiesfile. Learn more about requirements in our AndroidX FAQ.
In this quick start tutorial you will create a simple Android app that will open a PDF document stored in your Android project by using DocumentActivity. The sample code for this tutorial is available at our GitHub repository.
On the Android welcome screen, click Start a new Android Studio project:

Create a new Android Studio project with an Empty Activity and set the minimum SDK to API 16. Learn more about Apryse's system requirements in Android supported API FAQ.
For simplicity, we'll integrate the Apryse SDK into our project using
Gradle. You can learn more about how Gradle is used in Android Studio at the Gradle guides.Find yourgradle.propertiesfile in the root folder of your project and add your license key to this file:
Now open the
settings.gradlefile located in your project's root directory and add the Apryse Maven repository:
Then in your app module's
build.gradlefile (usuallyapp/build.gradle) add the following:You should also sync your project when you make changes in your Gradle files.
In order to support all the features in
DocumentActivity, we need to include the Android permissions listed in the table below. However if you would like to disable certain features and customize your document viewer, you should leave out unnecessary permissions. You can learn more about Android Mobile SDK permissions.In this sample we'll add all the permissions toAndroidManifest.xmlso we can support all the features in the viewer. In this file, we'll also need to add a reference to our Apryse license key. The resultingAndroidManifest.xmlfile should look something like this:
Opening a PDF from a URL
HTML to PDF conversion
Realtime collaboration
android.permission.INTERNET
Creating sound annotations
android.permission.RECORD_AUDIO
If you would like to customize the appearance of the viewer activity, define
PDFTronAppTheme(referenced byDocumentActivityinAndroidManifest.xml) inres/values/styles.xml:You can learn more about this in the customize the viewer's theme guide.
Now add a PDF file to the
res/rawfolder of your project (you can use our sample file) and call it sample.pdf, we are going to reference this file in the next step.

In
onCreateof your launcher activity, call [DocumentActivity.openDocument(Context, int)](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/DocumentActivity.html#openDocument(android.content.Context, int)) to open this PDF file with the document reader:This launchesDocumentActivitywith our sample PDF document with default viewer configurations, and you should see the following: You can also view your document inDocumentActivityby specifiying a local file path, an HTTP/HTTPS url, or a Content Uri:Please note that any changes made to files opened fromres/rawwill not be saved on the disk.The source code for this tutorial can be found on our GitHub repository.

Next steps
Customize your document reader by using ViewerConfig.
Last updated
Was this helpful?