我需要将二进制内容从我的应用程序发送到设备中打开该文件类型的任何应用程序.
我按照这些说明操作: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)
一些东西:
intent.setDataAndType()似乎在OS M和更低的设备上工作正常.在NI上也是如此TransactionTooLargeException最后,这是我需要完成的事情:
file:///storage/emulated/0/Download/TempFile.html关于我可能做错的任何想法?我已经尝试解决这个问题几天了,我已经阅读了大量的教程和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)