Android:打开没有本地副本的Office文档

时间:2017-03-27 15:32:33

标签: android excel android-intent ms-word powerpoint

背景: 我们正在开发一款应用程序,可以安全地从服务器下载文件,并允许用户在他们的Android设备上查看文件(只要他们安装了Word / Excel / Powerpoint) - 我们专门针对Microsoft产品不应该"泄漏"信息给第三方。

使用Intent在相关应用程序中打开文件,当我们返回应用程序时,我们撤销URI读取权限。

问题在于,当您在其中打开文档时,他们会制作文件的本地副本,因此可以重新打开文件,而无需通过我们应用程序的安全性。

作为一个例子," Recent" Word上的列表的位置为:

≫ data ≫ user ≫ 0 ≫ com.microsoft.office.word ≫ documents ≫ document.docx

显然我们想要阻止这一点,有没有人知道如何阻止Android Office制作一个"本地缓存"该文件的副本?

我们打开文件的代码如下所示:

Uri uri = Uri.fromFile(file);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    uri = FileProvider.getUriForFile(activity, appContext.getPackageName() + ".fileprovider", file);
}
intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setPackage(appPackage);
intent.setDataAndType(uri, mimeType);
activity.grantUriPermission(appPackage, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.startActivity(intent);

appPackage是应用程序的包名称,因为相同的代码用于Word,Excel和Powerpoint。

请注意,文件可以是doc,docx,xl​​s,xlsx,ppt或pptx,因为文档可以是历史文件。

提前感谢任何人提供的任何帮助。

0 个答案:

没有答案
相关问题