【发布时间】:2014-06-19 21:15:30
【问题描述】:
由于某种原因,我打开任何下载文件的代码,在这种情况下 .docx 不适用于 QuickOffice,我得到的例外是:
06-02 22:04:05.356:E/AndroidRuntime(2889):致命异常:主要 06-02 22:04:05.356: E/AndroidRuntime(2889): 进程: com.quickoffice.android, PID: 2889 06-02 22:04:05.356: E/AndroidRuntime(2889): java.lang.NullPointerException 06-02 22:04:05.356: E/AndroidRuntime(2889): at com.google.android.apps.docs.quickoffice.a.g.a(AbstractSaveAction.java:14) 06-02 22:04:05.356: E/AndroidRuntime(2889): 在 com.google.android.apps.docs.editors.menu.d.a(AbstractMenuItemController.java:28) 06-02 22:04:05.356: E/AndroidRuntime(2889): at com.google.android.apps.docs.editors.menu.c.a(AbstractButtonMenuItemController.java:24) 06-02 22:04:05.356: E/AndroidRuntime(2889): at com.google.android.apps.docs.editors.menu.y.a(MenuController.java:59) 06-02 22:04:05.356: E/AndroidRuntime(2889): at com.google.android.apps.docs.editors.menu.y.a(MenuController.java:59) 06-02 22:04:05.356: E/AndroidRuntime(2889): at com.google.android.apps.docs.editors.menu.z.run(MenuController.java:37)
我建立意图的代码是:
Intent install = new Intent(Intent.ACTION_VIEW);
String mimeType = getMimeType(tempFile);
Uri uri = Uri.parse("content://com.companyname/"+ fileName);
install.setDataAndType(uri, mimeType);
install.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(install, "Open File");
_progressDialog.getContext().startActivity(intent);
我的内容提供者代码是这样的:
public class DownloadedFileContentProvider extends ContentProvider {
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
File privateFile = new File(getContext().getCacheDir(), uri.getPath());
return ParcelFileDescriptor.open(privateFile, ParcelFileDescriptor.MODE_READ_WRITE);
}
//Other overridden methods that return false and null for the ContentProvider class.
}
我没有想法,Android上的Microsoft Office也是如此,文档根本打不开。 Office Suite 是唯一可以打开一切的应用程序。
【问题讨论】:
-
您可以尝试using
FileProvider而不是自己滚动,看看是否效果更好。
标签: android android-intent ms-word android-contentprovider document