我打算开发一个支持pdf阅读功能的Android应用程序,支持超链接。我想在pdf中显示嵌入的超链接,用户点击我的应用程序需要重定向到浏览器的超链接。 我不想使用谷歌docs.I已经找到一些开源的pdf sdk但我无法提供超链接的支持。如果有任何开源的sdk可用,也建议我提供超链接支持。
答案 0 :(得分:1)
这可以通过WebView或下载PDF并打开已安装应用程序的Intent来完成。但是,我使用的是第三方API,它无法打开超链接的PDF。我上面描述的两种方式可以通过
来实现if (!canDisplayPdf()) {
Intent i = new Intent(getBaseContext(), WebActivity.class);
i.putExtra("url", alist.get(position).toString());
//alist.get(position).toString() is hyperlinked pdf url
startActivity(i);
}
else
{
try
{
Toast.makeText(getBaseContext(), "Opening PDF... ", Toast.LENGTH_SHORT).show();
Intent inte = new Intent(Intent.ACTION_VIEW, Uri.parse(alist.get(position).toString()));
//inte.setDataAndType(Uri.parse(alist.get(position).toString()), "application/pdf");
startActivity(inte);
}
catch (ActivityNotFoundException e)
{
Log.e("Activity Not Found", e.getMessage());
}
// If canDisplayPDF function() will ensure whether device has PDF application or not.
public boolean canDisplayPdf() {
PackageManager packageManager = getApplication().getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
if (packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
return true;
}
else
{
return false;
}
}