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:

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());

Help DEV – Analista desenvolvedor Java / Android

http://helpdev.com.br/zarelli

Deixe uma resposta

O seu endereço de email não será publicado Campos obrigatórios são marcados *

Você pode usar estas tags e atributos de HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>