open Pdf File - Android Intent

Android examples for Intent:Open File

Description

open Pdf File

Demo Code


//package com.java2s;

import android.content.ActivityNotFoundException;

import android.content.Context;
import android.content.Intent;

import android.net.Uri;

public class Main {
    public static boolean openPdfFile(Context a, Uri pathToPdf) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(pathToPdf, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        try {/*from   ww w  .  java  2s . c  om*/
            a.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
        }
        return false;
    }
}

Related Tutorials