我正在尝试使用 android 查看文件单词以及 .txt 文件,如下所示:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.parse("file:///android_asset/usage.txt"), "plain/text");
getApplicationContext().startActivity(intent);
和
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.parse("file:///android_asset/USAGE_INSTRUCTIONS_FOR_SMART_RESPONDER.doc"), "plain/text");
getApplicationContext().startActivity(intent);
在活动的方法中。现在,我的设备上安装了 ES 文件管理器。但我不断收到错误:
05-09 01:24:53.516: W/System.err(28918): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///android_asset/USAGE_INSTRUCTIONS_FOR_SMART_RESPONDER.doc typ=plain/text flg=0x10000000 }
05-09 01:24:53.516: W/System.err(28918): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
05-09 01:24:53.516: W/System.err(28918): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
05-09 01:24:53.516: W/System.err(28918): at android.app.ContextImpl.startActivity(ContextImpl.java:949)
05-09 01:24:53.524: W/System.err(28918): at android.app.ContextImpl.startActivity(ContextImpl.java:931)
05-09 01:24:53.524: W/System.err(28918): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
05-09 01:24:53.524: W/System.err(28918): at com.pack.android.activity.ResponderActivity.onHelpMenuSelected(ResponderActivity.java:1733)
05-09 01:24:53.524: W/System.err(28918): at com.pack.android.activity.ResponderActivity.onOptionsItemSelected(ResponderActivity.java:1711)
05-09 01:24:53.532: W/System.err(28918): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
05-09 01:24:53.532: W/System.err(28918): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
05-09 01:24:53.532: W/System.err(28918): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
05-09 01:24:53.532: W/System.err(28918): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
05-09 01:24:53.539: W/System.err(28918): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
05-09 01:24:53.539: W/System.err(28918): at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:156)
05-09 01:24:53.539: W/System.err(28918): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
05-09 01:24:53.539: W/System.err(28918): at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
05-09 01:24:53.547: W/System.err(28918): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
05-09 01:24:53.547: W/System.err(28918): at android.widget.AbsListView$1.run(AbsListView.java:3423)
05-09 01:24:53.547: W/System.err(28918): at android.os.Handler.handleCallback(Handler.java:725)
05-09 01:24:53.547: W/System.err(28918): at android.os.Handler.dispatchMessage(Handler.java:92)
05-09 01:24:53.547: W/System.err(28918): at android.os.Looper.loop(Looper.java:137)
05-09 01:24:53.555: W/System.err(28918): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-09 01:24:53.555: W/System.err(28918): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 01:24:53.555: W/System.err(28918): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 01:24:53.555: W/System.err(28918): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-09 01:24:53.555: W/System.err(28918): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-09 01:24:53.563: W/System.err(28918): at dalvik.system.NativeStart.main(Native Method)
和
05-09 01:29:43.071: W/System.err(28918): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///android_asset/usage.txt typ=plain/text flg=0x10000000 }
05-09 01:29:43.071: W/System.err(28918): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
05-09 01:29:43.078: W/System.err(28918): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
05-09 01:29:43.078: W/System.err(28918): at android.app.ContextImpl.startActivity(ContextImpl.java:949)
05-09 01:29:43.086: W/System.err(28918): at android.app.ContextImpl.startActivity(ContextImpl.java:931)
05-09 01:29:43.086: W/System.err(28918): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
05-09 01:29:43.086: W/System.err(28918): at com.pack.android.activity.ResponderActivity.onHelpMenuSelected(ResponderActivity.java:1748)
05-09 01:29:43.086: W/System.err(28918): at com.pack.android.activity.ResponderActivity.onOptionsItemSelected(ResponderActivity.java:1711)
05-09 01:29:43.094: W/System.err(28918): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
05-09 01:29:43.094: W/System.err(28918): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
05-09 01:29:43.094: W/System.err(28918): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
05-09 01:29:43.094: W/System.err(28918): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
05-09 01:29:43.094: W/System.err(28918): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
05-09 01:29:43.102: W/System.err(28918): at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:156)
05-09 01:29:43.102: W/System.err(28918): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
05-09 01:29:43.102: W/System.err(28918): at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
05-09 01:29:43.102: W/System.err(28918): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
05-09 01:29:43.110: W/System.err(28918): at android.widget.AbsListView$1.run(AbsListView.java:3423)
05-09 01:29:43.110: W/System.err(28918): at android.os.Handler.handleCallback(Handler.java:725)
05-09 01:29:43.110: W/System.err(28918): at android.os.Handler.dispatchMessage(Handler.java:92)
05-09 01:29:43.118: W/System.err(28918): at android.os.Looper.loop(Looper.java:137)
05-09 01:29:43.118: W/System.err(28918): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-09 01:29:43.118: W/System.err(28918): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 01:29:43.118: W/System.err(28918): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 01:29:43.125: W/System.err(28918): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-09 01:29:43.125: W/System.err(28918): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-09 01:29:43.125: W/System.err(28918): at dalvik.system.NativeStart.main(Native Method)
我的资产文件夹中有这两个文件,但仍然无法打开它!任何帮助都会很棒!
编辑
使用正确的MIME_TYPE确实可以解决该错误,但现在我遇到了另一个错误:
05-09 01:42:27.647: W/System.err(29614): java.lang.RuntimeException: java.io.FileNotFoundException: /android_asset/USAGE_INSTRUCTIONS_FOR_SMART_RESPONDER.doc: open failed: ENOENT (No such file or directory)
05-09 01:42:27.647: W/System.err(29614): at com.tf.fastole2.CompoundBinaryUtil.openRandomAccessFile(CompoundBinaryUtil.java:15)
05-09 01:42:27.647: W/System.err(29614): at com.tf.fastole2.TFOleFileSystem.openFileSystem(TFOleFileSystem.java:81)
05-09 01:42:27.647: W/System.err(29614): at com.tf.fastole2.TFOleFsFactory.openFileSystem(TFOleFsFactory.java:32)
05-09 01:42:27.647: W/System.err(29614): at com.tf.write.filter.CheckFileType.isHwp50(CheckFileType.java:240)
05-09 01:42:27.655: W/System.err(29614): at com.tf.write.filter.CheckFileType.getType(CheckFileType.java:35)
05-09 01:42:27.655: W/System.err(29614): at com.tf.thinkdroid.write.viewer.action.Open$2.run(Unknown Source)
05-09 01:42:27.655: W/System.err(29614): at java.lang.Thread.run(Thread.java:856)
05-09 01:42:27.655: W/System.err(29614): Caused by: java.io.FileNotFoundException: /android_asset/USAGE_INSTRUCTIONS_FOR_SMART_RESPONDER.doc: open failed: ENOENT (No such file or directory)
05-09 01:42:27.655: W/System.err(29614): at libcore.io.IoBridge.open(IoBridge.java:416)
05-09 01:42:27.655: W/System.err(29614): at java.io.RandomAccessFile.<init>(RandomAccessFile.java:118)
05-09 01:42:27.655: W/System.err(29614): at com.tf.fastole2.CompoundBinaryUtil.openRandomAccessFile(CompoundBinaryUtil.java:11)
05-09 01:42:27.655: W/System.err(29614): ... 6 more
05-09 01:42:27.655: W/System.err(29614): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
05-09 01:42:27.655: W/System.err(29614): at libcore.io.Posix.open(Native Method)
05-09 01:42:27.655: W/System.err(29614): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
05-09 01:42:27.655: W/System.err(29614): at libcore.io.IoBridge.open(IoBridge.java:400)
05-09 01:42:27.655: W/System.err(29614): ... 8 more
05-09 01:42:27.655: W/System.err(29614): java.io.FileNotFoundException: /android_asset/USAGE_INSTRUCTIONS_FOR_SMART_RESPONDER.doc: open failed: ENOENT (No such file or directory)
05-09 01:42:27.655: W/System.err(29614): at libcore.io.IoBridge.open(IoBridge.java:416)
05-09 01:42:27.655: W/System.err(29614): at java.io.RandomAccessFile.<init>(RandomAccessFile.java:118)
05-09 01:42:27.655: W/System.err(29614): at java.io.RandomAccessFile.<init>(RandomAccessFile.java:150)
05-09 01:42:27.655: W/System.err(29614): at java.util.zip.ZipFile.<init>(ZipFile.java:130)
05-09 01:42:27.655: W/System.err(29614): at java.util.zip.ZipFile.<init>(ZipFile.java:103)
05-09 01:42:27.655: W/System.err(29614): at com.tf.io.CachedZipFile$RealZipFileImpl.<init>(CachedZipFile.java:274)
05-09 01:42:27.655: W/System.err(29614): at com.tf.io.CachedZipFile$RealZipFileImpl.<init>(CachedZipFile.java:269)
05-09 01:42:27.655: W/System.err(29614): at com.tf.io.CachedZipFile.create(CachedZipFile.java:61)
05-09 01:42:27.655: W/System.err(29614): at com.tf.io.CachedZipFile.create(CachedZipFile.java:37)
05-09 01:42:27.655: W/System.err(29614): at com.tf.write.filter.CheckFileType.isDocx(CheckFileType.java:322)
05-09 01:42:27.655: W/System.err(29614): at com.tf.write.filter.CheckFileType.getType(CheckFileType.java:47)
05-09 01:42:27.655: W/System.err(29614): at com.tf.thinkdroid.write.viewer.action.Open$2.run(Unknown Source)
05-09 01:42:27.655: W/System.err(29614): at java.lang.Thread.run(Thread.java:856)
05-09 01:42:27.655: W/System.err(29614): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
05-09 01:42:27.663: W/System.err(29614): at libcore.io.Posix.open(Native Method)
05-09 01:42:27.663: W/System.err(29614): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
05-09 01:42:27.663: W/System.err(29614): at libcore.io.IoBridge.open(IoBridge.java:400)
05-09 01:42:27.663: W/System.err(29614): ... 12 more