由于工作的需要,今天研究了一下如何打开手机上面的word文档,excel,ppt。刚开始的以为只要能调用wps office工具打开就行,如果手机上面没有wps office就提示用户自己去下载,可是当我已经实现功能的时候,结果需求并不是我想的那样,而是调用手机上面的有用户自己选择用何种工具打开。于是我就又研究一下如何让用户选择自己已经安装的工具打开。下面先上一段用wps office打开word ,excel,ppt的代码 // 专用wps工具打开word,excel,ppt
public boolean openFile(String path) {
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString(OPEN_MODE, READ_ONLY);
bundle.putBoolean(CLEAR_BUFFER, true);
bundle.putBoolean(CLEAR_TRACE, true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setClassName("cn.wps.moffice_eng",
"cn.wps.moffice.documentmanager.PreStartActivity");
File file = new File(path);
if (file == null || !file.exists()) {
return false;
}
Uri uri = Uri.fromFile(file);
System.out.println("uri---- |