我必须构建一个显示pdf文件列表的Android应用程序。这些pdf文件应该是安全的,换句话说 - 应用程序的用户不应该以任何方式获得pdf内容的副本(复制/剪切/打印等)。我现在的问题是
仅供参考,我将锁定当前版本的Adobe Redaer作为pdf查看器以查看pdf文件,因为它不允许复制/粘贴/打印。
这是我正在开发的第一款Android应用。所以,我是一个Android新手。任何帮助将不胜感激。
谢谢, 纳文
答案 0 :(得分:1)
您可以将此(这些)pdf文件复制到资源文件夹中,因此您的文件将成为应用程序的一部分,无法在外部访问,您也可以将它们视为普通文件(即打开任何文件)在你的情况下pdf查看器)。每当您想要访问上下文文件时,您都可以调用context.getAssets()
。
希望这些信息有所帮助。
更新:以下是我用于在downloads目录中打开文件的代码,如果安装在手机上,使用Adobe Reader测试,此代码可以在任何兼容的pdf阅读器中打开pdf文件。您将需要assets文件夹中的pdf文件的URI来运行代码。
String fileName = pdfUrl.substring(pdfUrl.lastIndexOf("/"));
Log.i("fileName", "" + fileName);
File file = new File("/sdcard/download" + fileName);
// File file = new
// File("/sdcard/download/airtel_latest000.mp3");
Intent intent;
if (file.exists()) {
Uri path = Uri.fromFile(file);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
downloaded = true;
} else {
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(pdfUrl));
downloaded = false;
}
try {
startActivityForResult(intent, 5);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
答案 1 :(得分:1)
您可能应将其存储在res/raw folder
中