how to implement pdf reader in my application using existing code of pdf readers. please help me as soon as possible!!
We have a need to embed PDF reader in one of our custom built Android application from local directory (Sdcard).
how to implement pdf reader in my application using existing code of pdf readers. please help me as soon as possible!!
We have a need to embed PDF reader in one of our custom built Android application from local directory (Sdcard).
Follow a PdfUtils class that I'm used to use to show PDF documents in my android applications.
import java.io.File;
import java.util.List;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Environment;
public class PdfUtils {
static public boolean isAnyPdfReaderAvailable(Context context) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("path-to-document"));
intent.setType("application/pdf");
PackageManager pm = context.getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
if (activities.size() > 0)
return true;
else
return false;
}
static public void loadPdfInReader(Context context, String doc) throws ActivityNotFoundException, Exception {
try {
Intent intent = new Intent();
intent.setPackage("com.adobe.reader");
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + doc);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
context.startActivity(intent);
} catch (ActivityNotFoundException activityNotFoundException) {
activityNotFoundException.printStackTrace();
throw activityNotFoundException;
} catch (Exception otherException) {
otherException.printStackTrace();
throw otherException;
}
}
}