Last active
May 12, 2025 20:00
-
-
Save gszauer/97f7646cec1a2fc8f1cabc5d250de381 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!Environment.isExternalStorageManager()) { | |
Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); | |
intent.setData(Uri.parse("package:" + getPackageName())); | |
startActivity(intent); // directs user to settings screen | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ContentValues values = new ContentValues(); | |
values.put(MediaStore.Files.FileColumns.DISPLAY_NAME, "Report.pdf"); | |
values.put(MediaStore.Files.FileColumns.MIME_TYPE, "application/pdf"); | |
values.put(MediaStore.Files.FileColumns.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS); | |
// RELATIVE_PATH "Documents" directs it to /storage/emulated/0/Documents | |
Uri uri = getContentResolver().insert(MediaStore.Files.getContentUri("external"), values); | |
if (uri != null) { | |
try (OutputStream out = getContentResolver().openOutputStream(uri)) { | |
// Write your file data to the stream | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment