1

Создал svg файл, нужно его отправить по почте, но я что-то делаю не так:

File file=new File(getFilesDir(), FILENAME);
    Intent email = new Intent(Intent.ACTION_SEND);

   if (file.exists()) {
       email.putExtra(Intent.EXTRA_EMAIL, new String[]{etMail.getText().toString()});
       email.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file));
       email.putExtra(Intent.EXTRA_SUBJECT, "Subject");
       email.putExtra(Intent.EXTRA_TEXT, "text");
       email.setType("message/rfc822");
      // email.setType("*/*");
       startActivity(Intent.createChooser(email, "Выберите email клиент :"));}

Приложение падает по строке

 email.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file));

с ошибкой:

android.os.FileUriExposedException: file:///data/user/0/ru.test/files/file.svg exposed beyond app through ClipData.Item.getUri()

1 ответ 1

2

Начиная с API 24 (по моему) запрещается использование в Intent ссылок типа file://, необходимо их маскировать специальным FileProvider, который умеет превращать ссылки file:// в content://

Инструкции здесь

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.