Buenas gente me podrían ayudar con esto, intento mandar un archivo txt a través por un mensaje de WhatsApp mediante código sin embargo cuando trato de obtener la ruta del archivo me me tira este error
android.os.FileUriExposedException: file:///data/user/0/com.example.plantas/files/registros.txt exposed beyond app through ClipData.Item.getUri()
la ruta donde se encuentra el archivo dentro del teléfono es
/data/data/com.example.plantas/files/registros.txt
cuando trato de obtener la ruta me da file:///data/user/0/com.example.plantas/files/registros.txt
, les dejo la el código de la función que utilizo
public void Enviar(View view) throws IOException {
File file = new File(getFilesDir(),"registros.txt");//Uso la memoria interna dentro de la carpeta files
FileWriter archivo = null;
PrintWriter pw = null;
try{
archivo= new FileWriter(file);
pw = new PrintWriter((archivo));
pw.println("texto");
pw.flush();
}catch (IOException e){
e.printStackTrace();
}
Uri uri = Uri.fromFile(file);//Aqui guardo la ruta del archivo
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setPackage("com.whatsapp");
try {
startActivity(share);
} catch (android.content.ActivityNotFoundException ex) {
ex.printStackTrace();
Snackbar.make(view, "El dispositivo no tiene instalado WhatsApp", Snackbar.LENGTH_LONG).show();
}
}