gpt4 book ai didi

android - 找不到处理 Intent 错误的 Activity

转载 作者:行者123 更新时间:2023-11-30 03:37:20 25 4
gpt4 key购买 nike

我正在尝试使用 android 查看文件 word 以及 .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);

在 Activity 的方法中。现在,我的设备上安装了 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)

我的 assets 文件夹中有这 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

最佳答案

问题是您正试图通过 Intent 向无权访问您的文件的第 3 方应用程序授予访问权限。Android 的安全模型不允许任何其他应用访问您的私有(private)数据( Assets /资源......)这里的 root 是一个异常(exception)。

因此,为了让您的文件可供此类应用程序使用,请考虑将您的文件复制到公共(public)目录 CacheDir也许是最合适的选择。

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

Android: how to copy files in assets to sdcard

同时查看 Android's Security Model

P.S 不要忘记 WRITE_EXTERNAL_STORAGE 权限..

祝你好运

关于android - 找不到处理 Intent 错误的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16449200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com