次のコードは Android 5、6 で完全に動作しますが、Android 7.1 ではクラッシュします。
Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(""));
intent1.setDataAndType(Uri.parse("file:///" + "sdcard/path/"+fName), "application/pdf");
startActivity(intent1);
ログキャット:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.amey.newunipunebuddy, PID: 19574
android.os.FileUriExposedException: file:///sdcard/unipunebuddy_data/timetables/Timetable.pdf exposed beyond app through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9022)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8983)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1519)
at android.app.Activity.startActivityForResult(Activity.java:4225)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:4183)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
at android.app.Activity.startActivity(Activity.java:4522)
at android.app.Activity.startActivity(Activity.java:4490)
at com.amey.newunipunebuddy.Timetable$DownloadTask.onPostExecute(Timetable.java:498)
at com.amey.newunipunebuddy.Timetable$DownloadTask.onPostExecute(Timetable.java:415)
at android.os.AsyncTask.finish(AsyncTask.java:660)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:677)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6145)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
W/DynamiteModule: com.google.firebase.auth のローカル モジュール記述子クラスが見つかりません。アプリケーションは終了しました。