I want to write a read-only document reader.
The document is an online-document.
The file format contains *.doc, *.docx, *.ppt, *.pptx, *.xls, *.xlsx, *.pdf, *.txt.
Now I do it by download document to phone.
And use below code to open it.
But this method open file can be modify, I want to open with read-only.
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;
}
Because the document’s URL and phone’s wifi may in the same local network, so the GoogleDocs is not useful for me.
How can I do to read online document with read-only?
I think about that you should define permission in AndroidManifest.xml of Android.
use below permission:
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_PHONE_STATE