android - 如何在android中打开word文档文件?
问题描述
我在服务器中有一个 word 文档(.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();
}
解决方案
我有这个链接显示如何在 Android 中打开任何文件:http ://www.androidsnippets.com/open-any-type-of-file-with-default-intent.html
此外,还有一个类似的案例,由 PDF 文件完成:Android : how to open pdf file from server in android
我希望这些链接对你有用。
祝你好运,G。
推荐阅读
- sql - 在 SQL Server 查询中使用模式和 patindex 函数时如何忽略特定的字符串值?
- php - Laragon - 我如何在启动时为网站提供服务?
- javascript - 使用 javascript 对 html 进行排序
- excel - 从函数添加控件(不是子!)
- python - 基于特殊模型Django的动态查询集
- python - 如何在python程序中应用递归
- x86 - 为什么 x86 分页没有特权环的概念?
- c# - 如何在 C# 中转换具有 C 类型占位符(%d、%x 等)的字符串
- java - HandlerInterceptor spring - 排除管理端口上的请求
- teamcity - 在 TeamCity 中使用 GitVersion 时,如何让它在 TC 内部版本号中包含构建元数据