找不到活动来处理意图错误

时间:2013-05-08 20:01:11

标签: android android-intent

我正在尝试使用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)

我的资源文件夹中有这2个文件,但仍然无法打开它! 任何帮助都会很棒!

修改

使用正确的 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

4 个答案:

答案 0 :(得分:1)

问题在于您尝试通过意图将访问权限授予无权访问您文件的第三方应用程序。 Android的安全模型不允许任何其他应用访问您的私人数据(资产/资源....) root这是一个例外。

因此,为了使您的文件可供此类应用使用,请考虑将文件复制到公共目录CacheDir,这可能是最合适的选项。

通过这样做,您可以使用意图以您现在使用它们的方式查看数据。 有关将文件复制到外部目录的更多信息,请查看此处:

Android: how to copy files in assets to sdcard

同时在此处查看Android's Security Model

P.S不要忘记WRITE_EXTERNAL_STORAGE 渗透..

祝你好运

答案 1 :(得分:0)

您应该使用text/plain代替plain/text

答案 2 :(得分:0)

如异常日志中所述,

java.io.FileNotFoundException: /android_asset/USAGE_INSTRUCTIONS_FOR_SMART_RESPONDER.doc: open failed: ENOENT (No such file or directory)

无法找到该文件。验证文件是否确实存在于该位置。另外,正如Brigham所提到的,使用text / plain。

答案 3 :(得分:0)

例外说文件不存在。注意您指向内部存储器中的/ android_asset /文件夹。

您确定不将此文件放在SDCard上吗?