Я добавил раздел FileProvider в свой AndroidManifest.xml в теге приложений:
Код: Выделить всё
android:name="androidx.core.content.FileProvider"
android:authorities="com.domain.name.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
Код: Выделить всё
Код: Выделить всё
File filesDir = getApplicationContext().getFilesDir();
File shareDir = new File(filesDir, "shared/");
File file = new File(shareDir, "filename.txt");
Uri fileUri = FileProvider.getUriForFile(getApplicationContext(),
"com.domain.name.fileprovider",
file);
// Create the text message with a string
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sendIntent.setData(fileUri);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getString(R.string.share_title)));
Я работал с общим доступом к файлам и FileProvider, но еще не заметил, что я пропустил.
Что я сделал, что означает, что я не получил права на чтение правильно разрешение получателю намерения? Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/792 ... ileprovier
Мобильная версия