相关疑难解决方法(0)

尝试使用Intents发送二进制内容时的TransactionTooLargeException

我需要将二进制内容从我的应用程序发送到设备中打开该文件类型的任何应用程序.

我按照这些说明操作:https: //developer.android.com/training/sharing/send.html#send-binary-content

这是我的代码:

final FileType fileType
final File file;

final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(AncestryApplication.getAppContext(), AncestryApplication.getAppContext().getApplicationContext().getPackageName() + ".provider", file));

intent.setType(fileType.getMimeType());
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

一些东西:

  1. 如果我将意图操作从ACTION_VIEW更改为ACTION_SEND,我会得到错误的应用程序列表以打开我的文件
  2. ACTION_SEND似乎有效,但只适用于较小的文件大小
  3. intent.setDataAndType()似乎在OS M和更低的设备上工作正常.在NI上也是如此TransactionTooLargeException

最后,这是我需要完成的事情:

  • 我已经保存了一个文件,它存储在 file:///storage/emulated/0/Download/TempFile.html
  • 由于文件可能太大,我需要的文件只是位置发送给第三方应用程序(如Adobe PDF阅读器)打开文件
  • 没有M或更低的问题,N上的大量问题

关于我可能做错的任何想法?我已经尝试解决这个问题几天了,我已经阅读了大量的教程和SO建议,没有任何最终答案.

谢谢.

编辑:这是我的堆栈跟踪:

AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.android.apps.myapp, PID: 26785
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 27943540 bytes
  at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3752)
  at android.os.Handler.handleCallback(Handler.java:751)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:154)
  at android.app.ActivityThread.main(ActivityThread.java:6077)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Caused by: android.os.TransactionTooLargeException: data …
Run Code Online (Sandbox Code Playgroud)

android android-intent

0
推荐指数
1
解决办法
2292
查看次数

标签 统计

android ×1

android-intent ×1