1

我使用下面的代码通过调用其他应用程序来打开 .doc 文件。
但我不希望文件被修改。
所以我想将文件设置为只读。
或任何其他避免用户修改文件的方法。
文件格式可以是*.doc、*.docx、*.ppt、*.pptx、*.pdf、*.txt。

File file = new File(FilePath);
String mimetype = ".doc\tapplication/msword";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), mimetype);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
4

2 回答 2

1

您无法阻止用户更改存储在外部存储设备上的数据,前提是他们找到愿意提供帮助的应用程序 - 例如现成的文件管理器应用程序。

只要安全模型保持不变,存储在应用程序私有存储区域中的数据就可以防止写入,或防止其他应用程序写入和读取。

但是,如果 Intent 指向的文件位于不同应用程序的私有存储区域中,则某些应用程序不愿意尝试访问该文件,即使已设置文件和目录权限位以便 Android 系统允许它们访问。(例如,至少某些版本的 GMail 拒绝附加不在外部存储上的文件,尽管如果文件是全球可读的,他们可以被诱骗这样做。)

于 2012-05-14T03:35:36.547 回答
0

Copy the document to a cloud storage site. named doc.docx

Then rename it to doc.docx1, this is your template. You can copy it and remove the docx1 and edit the copy at will, leaving the template in alone.

于 2015-01-24T04:36:48.253 回答