Android上的文档阅读器

Android上的文档阅读器,android,Android,我想写一个只读文档阅读器。 该文档是在线文档。 文件格式包括*.doc、*.docx、*.ppt、*.pptx、*.xls、*.xlsx、*.pdf、*.txt。 现在我通过将文档下载到手机上来完成此操作。 并使用下面的代码打开它。 但是这个方法打开文件可以修改,我想以只读方式打开 File file = new File(TempFilePath); String mimetype = mime_type(TempFileName); Intent intent = new Intent(In

我想写一个只读文档阅读器。
该文档是在线文档。
文件格式包括*.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;
}
File File=新文件(TempFilePath);
字符串mimetype=mime_类型(TempFileName);
意向意向=新意向(意向.行动\视图);
setDataAndType(Uri.fromFile(file),mimetype);
intent.setFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
公共字符串mime_类型(字符串名称){
字符串类型=null;
字符串[]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 of cedocument.spreadsheetml.sheet”,“.pptx\tapplication/vnd.openxmlformats of cedocument.presentationml.presentation”,“.docx\tapplication/vnd.openxmlformats of cedocument.wordprocessingml.document”};
int i;
对于(i=0;i
因为文档的URL和手机的wifi可能在同一个本地网络中,所以GoogleDocs对我没有用处。

如何使用只读方式阅读在线文档?

我认为您应该在Android的AndroidManifest.xml中定义权限。 使用以下权限: android.permission.WRITE\u外部存储
android.permission.READ_PHONE_STATE

看看RandomAccessFile(File File,String mode)方法,它有一个模式“r”,以只读模式打开文件。但是如何读取文档呢?我还尝试了“File.setReadOnly();”。还有setWritable()方法,选中它。您可以尝试以只读模式从该文件创建RandomAccessFile并使用它。对于具有权限的用户,它不起作用