gpt4 book ai didi

android 在另一个应用程序上共享内容时显示错误

转载 作者:行者123 更新时间:2023-11-30 00:36:52 24 4
gpt4 key购买 nike

Android 在将数据共享到另一个应用程序时在 android nougat 中运行应用程序时显示致命异常。它在牛轧糖下面完美运行。

这是我的代码

  Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Student Details of " + currentDate);
sendIntent.putExtra(Intent.EXTRA_STREAM, u1);
sendIntent.setType("text/plain");
startActivity(sendIntent); // Gives error on this line

这是错误显示。

04-08 18:31:38.371 18464-18464/manager.attendance.com E/AndroidRuntime: FATAL EXCEPTION: main
Process: manager.attendance.com, PID: 18464
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=5, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {manager.attendance.com/manager.attendance.com.activity.MainActivity}: android.os.FileUriExposedException: file:///storage/emulated/0/Exported%20Data/Data-08-Apr-2017.csv exposed beyond app through ClipData.Item.getUri()
at android.app.ActivityThread.deliverResults(ActivityThread.java:4094)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4137)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1529)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: android.os.FileUriExposedException: file:///storage/emulated/0/Exported%20Data/Data-08-Apr-2017.csv exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1813)
at android.net.Uri.checkFileUriExposed(Uri.java:2360)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8957)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8942)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1583)
at android.app.Activity.startActivityForResult(Activity.java:4228)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4187)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4515)
at android.app.Activity.startActivity(Activity.java:4483)
at manager.attendance.com.activity.MainActivity.exportToCsvAndSend(MainActivity.java:171)
at manager.attendance.com.activity.MainActivity.onRequestPermissionsResult(MainActivity.java:191)

最佳答案

试试这个

startActivity(Intent.createChooser(shareIntent, 
getResources().getText(R.string.send_to)));

代替

startActivity(sendIntent); 

已记录 here

关于android 在另一个应用程序上共享内容时显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43294591/

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