Setting up realtime document collaboration in Android

Prerequisites

  • Minimum API: 21
  • Java 8

Step 1: Integration

Integrate collaboration package with Gradle

  1. Integrate Apryse core and the tools library as described in our Gradle get started guide.
  2. In your app module's build.gradle file (usually app/build.gradle), set the minSdkVersion to 21+ and enable compatibility for Java 8 features. Then, add the dependency for Apryse's collaboration package:

Groovy

1android {
2 defaultConfig {
3 minSdkVersion 21
4 }
5 compileOptions {
6 sourceCompatibility JavaVersion.VERSION_1_8
7 targetCompatibility JavaVersion.VERSION_1_8
8 }
9}
10
11dependencies {
12 implementation "com.pdftron:collab:11.0.0"
13}

Integrate collaboration package manually

  1. Integrate Apryse core and tools packages as described in Android manual integration guide.
  2. Copy pdftron-collab.aar directly into your app module's libs directory. You will see other Apryse AARs here such as pdftron.aar and tools.aar
  3. In your app module's build.gradle file (usually app/build.gradle), make sure the minSdkVersion is 21+ using Java 8 features. And add a dependency to Apryse collaboration package:

Groovy

1android {
2 defaultConfig {
3 minSdkVersion 21
4 }
5 compileOptions {
6 sourceCompatibility JavaVersion.VERSION_1_8
7 targetCompatibility JavaVersion.VERSION_1_8
8 }
9}
10
11dependencies {
12 implementation "com.pdftron:collab@aar"
13
14 // room
15 implementation "android.arch.persistence.room:runtime:2.4.2"
16 annotationProcessor "android.arch.persistence.room:compiler:2.4.2"
17 implementation "android.arch.persistence.room:rxjava2:2.4.2"
18}

Step 2: Add the viewer

  1. Update your AndroidManifest.xml as described in Step 1 of this guide.
  2. Create the CollabViewerTabHostFragment2, and start it like any other Android Fragment.
1// Create a viewer fragment using CollabViewerBuilder2 and add it to an activity
2public void addViewerFragment(AppCompatActivity activity, Uri fileUri) {
3 // Create a custom ViewerConfig used to initialize the viewer fragment
4 ViewerConfig config = new ViewerConfig.Builder()
5 .multiTabEnabled(false)
6 .build();
7 // Create the Fragment using CollabViewerBuilder2
8 CollabViewerTabHostFragment2 tabHostFragment =
9 CollabViewerBuilder2.withUri(fileUri)
10 .usingConfig(config)
11 .build(activity);
12 // Add the Fragment to your activity
13 FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
14 ft.replace(R.id.fragment_container, tabHostFragment, null);
15 ft.commit();
16}

where R.id.fragment_container is the resource id of a layout in your activity that will contain your fragment:

For example:

XML

1<?xml version="1.0" encoding="utf-8"?>
2<!-- This FrameLayout will contain our viewer fragment -->
3<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent"/>

Next steps

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales