Android – android.os.FileUriExposedException: file:///storage/emulated/0/{MY_FILE} exposed beyond app through Intent.getData()

files java file intent data

Problema:

FATAL EXCEPTION: Thread-2
Process: br.com.helpdev.teste, PID: 26078
android.os.FileUriExposedException: file:///storage/emulated/0/{MY_FILE} exposed beyond app through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1813)
at android.net.Uri.checkFileUriExposed(Uri.java:2360)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8981)
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.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java:4187)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:732)
at android.app.Activity.startActivity(Activity.java:4515)
at android.app.Activity.startActivity(Activity.java:4483)
at br.com.helpdev.teste.sistema.pacote.PacotesUtils.instalarPacote(PacotesUtils.java:29)
at br.com.helpdev.teste.sistema.pacote.GerenciadorPacotes.install(GerenciadorPacotes.java:154)
at br.com.helpdev.teste.sistema.pacote.GerenciadorPacotes$2.run(GerenciadorPacotes.java:172)

Solução:
O correto seria utilizar o FileProvider mas uma solução “workaround” bem simples seria: Continue reading