Create a share intent that also allows to save a document on Android

Viewed 237

Is there any way to create a share intent that gives the user the option to save the file somewhere in the device? Like an intent with ACTION_CREATE_DOCUMENT. My situation is the following: I have a file that is NOT visible to the user, saved in the app's documents folder via getExternalFilesDir, and I want to allow the user to either share that file, or save it directly in an accessible folder (it would be nice to suggest the user a path, like the file explorer opening directly in the public Download folder, but it is not needed). All of this should be wrapped inside the share intent, as I am only allowed to edit that as of now. The code looks something like this:

String packageName = Utils.currentContext.getApplicationContext().getPackageName();
        Uri uri = FileProvider.getUriForFile(Utils.currentContext, packageName + ".provider", file);
        Intent intentShareFile = new Intent(Intent.ACTION_SEND);
        intentShareFile.setType(type);
        intentShareFile.putExtra(Intent.EXTRA_STREAM, uri);
        intentShareFile.putExtra(Intent.EXTRA_SUBJECT, text);
        intentShareFile.putExtra(Intent.EXTRA_TEXT, text);
        intentShareFile.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

        Intent shareIntent = Intent.createChooser(intentShareFile, "Sharing file");
        Utils.currentActivity.startActivity(shareIntent);

I tried working with putExtra as well as addCategory with no success.

0 Answers
Related