Android PDFViewer Sample

Android PDFViewer is a strong application for reading .pdf files stored in SD cards of the device. The following article demonstrates a simple android pdfviewer application for android 4.0 helps to read .pdf files from internet in android device in 3G, Wi-Fi network.

To build the application , Click File – > New Project in Eclipse for Android IDE.

  • Put the name of the project & select Target device as Android 4.0
  • Now put the following code in Main.xml












Now, Modify the file as follows: 

package com.example.pdflistexample;


import android.os.Bundle;



import java.util.ArrayList;

import java.util.List;


import android.content.Intent;



import android.os.Environment;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.ListView;

public class PDFListExampleActivity extends ListActivity {

ArrayAdapter<String> adapter;

int clickCounter =0;

ArrayList<String> listItems = new ArrayList<String>();

private File[] imagelist;

String[] pdflist;

/** Called when the activity is first created. */


public void  onCreate(Bundle savedInstanceState) {


setContentView(R.layout. main);

File images = Environment.getExternalStorageDirectory();

imagelist = images.listFiles(new FilenameFilter(){

public boolean  accept(File dir, String name)


return ((name.endsWith(“.pdf”)));



pdflist = new String[imagelist.length];

for(int i=0;i<imagelist.length;i++)


pdflist[i]= imagelist[i].getName();


this.setListAdapter(new ArrayAdapter<String>(this android.R.layout. simple_list_item_1,pdflist));



protected  void onListItemClick(ListView l, View v, int position, long id)


super.onListItemClick(l, v, position, id);

PackageManager packageManager = getPackageManager();

Intent testIntent = new Intent(Intent.ACTION_VIEW);


List list = packageManager.queryIntentActivities(testIntent,PackageManager. MATCH_DEFAULT_ONLY);

if(list.size()>0 && imagelist[(int)id].isFile()){

Intent intent = new Intent();


Uri uri = Uri.fromFile(imagelist[(int)id].getAbsoluteFile());

intent.setDataAndType(uri, “application/pdf”);





  • Before running the application , make sure that you have downloaded some .pdf files in SD Card or installed pdfviewer in the device.
  • Otherwise download from Android Marketplace & test the app..





About Anindita
Anindita Basak is working as Big Data Cloud Consultant in Microsoft. Worked in multiple MNCs as Developer & Senior Developer on Microsoft Azure, Data Platform, IoT & BI , Data Visualization, Data warehousing & ETL & of course in Hadoop platform.She played both as FTE & v- employee in Azure platform teams of Microsoft.Passionate about .NET , Java, Python & Data Science. She is also an active Big Data & Cloud Trainer & would love share her experience in IT Training Industry. She is an author, forum contributor, blogger & technical reviewer of various books on Big Data Hadoop, HDInsight, IoT & Data Science, SQL Server PDW & PowerBI.

3 Responses to Android PDFViewer Sample

  1. Pingback: Android PDFViewer Sample « Anindita's Blog | Apple Bosom

  2. Pingback: Buy Targeted Facebook Fans

  3. Pingback: Buy Facebook Fans

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: