Как открыть файл документа Word в Android?
У меня есть слово документ (.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();
}
1 ответ
У меня есть эта ссылка, которая показывает, как открыть любой файл в Android: http://www.androidsnippets.com/open-any-type-of-file-with-default-intent.html
Также, есть аналогичный случай, который делается с помощью файла PDF: Android: как открыть файл PDF с сервера в Android
Я надеюсь, что эти ссылки будут работать для вас.
Удачи, Г.