0

我想写一个只读文档阅读器。
该文档是在线文档。
文件格式包含*.doc、*.docx、*.ppt、*.pptx、*.xls、*.xlsx、*.pdf、*.txt。
现在我通过将文件下载到手机来做到这一点。
并使用下面的代码打开它。
但是这个方法打开文件是可以修改的,我想以只读方式打开。

File file = new File(TempFilePath);
String mimetype = mime_type(TempFileName);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), mimetype);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

public String mime_type(String name) {
String type = null;
String[] mime = {".htm\ttext/html", ".html\ttext/html", ".doc\tapplication/msword", ".ppt\tapplication/vnd.ms-powerpoint", ".xls\tapplication/vnd.ms-excel", ".txt\ttext/plain", ".pdf\tapplication/pdf", ".xlsx\tapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ".pptx\tapplication/vnd.openxmlformats-officedocument.presentationml.presentation", ".docx\tapplication/vnd.openxmlformats-officedocument.wordprocessingml.document"};

int i;
for(i = 0; i < mime.length; i++) {
if(name.toLowerCase().endsWith(mime[i].split("\t")[0])) {
return mime[i].split("\t")[1];
}
}
return type;
}

因为文档的 URL 和手机的 wifi 可能在同一个本地网络中,所以 GoogleDocs 对我没有用。
如何以只读方式阅读在线文档?

4

1 回答 1

1

我认为您应该在 Android 的 AndroidManifest.xml 中定义权限。使用以下权限:android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_PHONE_STATE

于 2012-05-15T07:16:04.950 回答