1
當Android應用程序在android nougat中運行應用程序時,Android會顯示致命異常。它完美地運行在牛軋糖之下。android在另一個應用程序上共享內容時顯示錯誤
這裏是我的代碼
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{[email protected]: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)
https://stackoverflow.com/a/38203793/115145 – CommonsWare