如何使用现有的pdf阅读器代码在我的应用程序中实现pdf阅读器。请尽快帮助我!!
我们需要在本地目录(Sdcard)中将PDF阅读器嵌入到我们定制的Android应用程序中。
答案 0 :(得分:0)
按照我以前用来在我的Android应用程序中显示PDF文档的PdfUtils类。
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;
}
}
}