> 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/compare-files/file-comparison-a.md).

# File comparison in Android

Visually compare pages with ease using the resolution-independent comparison tool. Integrate UI components in your app with Standalone activity and Comparison options dialog. Follow Android best pract

You can visually compare pages. This resolution independent comparison allows you to quickly spot differences between pages.

There are two main ways to integrate the out-of-box UI components in your application:

1. [Standalone activity](https://docs.apryse.com)
2. [Comparison options dialog](https://docs.apryse.com)

## Standalone activity

The [`DiffActivity`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/DiffActivity.html) is a standalone component that handles from picking two files to generating the comparison result.

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

1. Define the activity

{% 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 %}

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

```xml
<activity android:name="com.pdftron.pdf.controls.DiffActivity" android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize" android:theme="@style/PDFTronAppTheme" android:windowSoftInputMode="adjustPan" />
```

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

1. Show the activity

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

```java
DiffActivity.open(this);
```

{% endcode %}
{% endtab %}

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

```kotlin
DiffActivity.open(this)
```

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

## Comparison options dialog

If you have your own viewer already and only want to show the comparison options in your application, the [`DiffOptionsDialogFragment`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/dialog/diffing/DiffOptionsDialogFragment.html) can be used.

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

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

```java
public void show(final Context context, FragmentManager fragmentManager, final ArrayList<Uri> files) {
    DiffOptionsDialogFragment fragment = DiffOptionsDialogFragment.newInstance(
        files.get(0), files.get(1)
    );
    fragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.PDFTronAppTheme);
    fragment.setDiffOptionsDialogListener(new DiffOptionsDialogFragment.DiffOptionsDialogListener() {
        @Override
        public void onDiffOptionsConfirmed(int color1, int color2, int blendMode) {
            compareFiles(context, files, color1, color2, blendMode);
        }
    });
    fragment.show(fragmentManager, DiffOptionsDialogFragment.TAG);
}
```

{% endcode %}
{% endtab %}

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

```kotlin
fun show(context: Context, fragmentManager: FragmentManager, files: ArrayList<Uri>) {
    val fragment = DiffOptionsDialogFragment.newInstance(
            files[0], files[1]
    )
    fragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.PDFTronAppTheme)
    fragment.setDiffOptionsDialogListener { color1, color2, blendMode -> compareFiles(context, files, color1, color2, blendMode) }
    fragment.show(fragmentManager, DiffOptionsDialogFragment.TAG)
}
```

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

where `compareFile` is:

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

```java
private final CompositeDisposable mDisposable = new CompositeDisposable();

private void compareFiles(Context context, ArrayList<Uri> files, int color1, int color2, int blendMode) {
    mDisposable.add(DiffUtils.compareFiles(context, files, color1, color2, blendMode)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Consumer<Uri>() {
            @Override
            public void accept(Uri uri) throws Exception {
                // do something with the output
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {

            }
        }));
}
```

{% endcode %}
{% endtab %}

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

```kotlin
private val mDisposable = CompositeDisposable()

private fun compareFiles(context: Context, files: ArrayList<Uri>, color1: Int, color2: Int, blendMode: Int) {
    mDisposable.add(DiffUtils.compareFiles(context, files, color1, color2, blendMode)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                // do something with the output
            }, { }))
}
```

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

`AsyncTask` pattern can be used instead of `Disposable` pattern if desired.


---

# 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/compare-files/file-comparison-a.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.
