Skip to content
Related Articles

Related Articles

Show PDF Using Intent in Android

Improve Article
Save Article
  • Last Updated : 29 Dec, 2021
Improve Article
Save Article

Android is an open-source operating system, based on the Linux kernel and used in mobile devices like smartphones, tablets, etc. Further, it was developed for smartwatches and Android TV. Each of them has a specialized interface. Android has been one of the best-selling OS for smartphones. Android OS was developed by Android Inc. which Google bought in 2005. In android when have to view Pdf we use Any Pdf viewing library for viewing any pdf. Here we are going to learn how to view pdf without using any third-party library.

In Android, it is quite usual for users to witness a jump from one application to another as a part of the whole process, for example, searching for a location on the browser and witnessing a direct jump into Google Maps or receiving payment links in Messages Application (SMS) and on clicking jumping to PayPal or GPay (Google Pay). This process of taking users from one application to another is achieved by passing the Intent to the system. Intents, in general, are used for navigating among various activities within the same application, but note, is not limited to one single application, i.e., they can be utilized from moving from one application to another as well.  

Intents could be Implicit, for instance, calling intended actions and explicit as well, such as opening another activity after some operations like onClick or anything else. Below are some applications of Intents:

  1. Sending the User to Another App
  2. Getting a Result from an Activity
  3. Allowing Other Apps to Start Your Activity

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
        android:text="Show Pdf"
        app:layout_constraintTop_toTopOf="parent" />

Step 3: Working with the file

Go to the file and refer to the following code. Below is the code for the file 


package com.prepare.makedirectory;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
    TextView click;
    protected void onCreate(Bundle savedInstanceState) {
        click.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
    private void viewpdf() {
        // add the link of pdf 
        Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(value));
        // start activity


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!