У меня есть текстовый документ (.doc
или .docx
) на сервере. Мне нужно открыть в моем приложении Android, нажав одну кнопку. DOC файл должен открыть. Как это сделать? кто-нибудь, пожалуйста, помогите мне.
Я попробовал этот код:
File file = new File(Environment.getExternalStorageDirectory(),
"Document.docx");
try {
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent objIntent = new Intent(Intent.ACTION_VIEW);
// replace "application/msword" with
// "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
// for docx files
// objIntent.setDataAndType(path,"application/msword");
objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objIntent);
} else {
Toast.makeText(PMComplitionProjectActivity.this, "File NotFound",
Toast.LENGTH_SHORT).show();
}
} catch (ActivityNotFoundException e) {
Toast.makeText(PMComplitionProjectActivity.this,
"No Viewer Application Found", Toast.LENGTH_SHORT)
.show();
} catch (Exception e) {
e.printStackTrace();
}