ρяσ*_*я K 30
与iOS不同,Android本身不支持渲染.doc或.ppt文件.您正在寻找一种公共意图,允许您的应用重用其他应用的活动来显示这些文档类型.但这只适用于安装了支持此Intent的应用的手机.
http://developer.android.com/guide/topics/intents/intents-filters.html
或者如果您已安装某个应用程序,则使用此Intent:
//Uri uri = Uri.parse("file://"+file.getAbsolutePath());
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
String type = "application/msword";
intent.setDataAndType(Uri.fromFile(file), type);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
Jar*_*ows 13
这是一种为您处理此问题的方法:
public void openDocument(String name) {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
File file = new File(name);
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (extension.equalsIgnoreCase("") || mimetype == null) {
// if there is no extension or there is no definite mimetype, still try to open the file
intent.setDataAndType(Uri.fromFile(file), "text/*");
} else {
intent.setDataAndType(Uri.fromFile(file), mimetype);
}
// custom message for the intent
startActivity(Intent.createChooser(intent, "Choose an Application:"));
}
Run Code Online (Sandbox Code Playgroud)
小智 10
从可用应用程序列表中打开文档用户必须从应用程序列表中选择应用程序
File targetFile = new File(path);
Uri targetUri = Uri.fromFile(targetFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/*");
startActivityForResult(intent, DOC);
Run Code Online (Sandbox Code Playgroud)
您可以将文件从原始资源复制到 sdcard,然后在 ACTION_VIEW Intent 上调用 startActivity(),该 Intent 具有指向可读副本的 Uri,并且还具有正确的 MIME 类型。
当然,这仅适用于具有 Word 文档查看器的设备。
| 归档时间: |
|
| 查看次数: |
53960 次 |
| 最近记录: |