Source:
<code>private void initFabToSave(final ArrayList<Uri> uris) { clearFabActionItems(); floatingActionButton.getMainFab().setImageResource(R.drawable.ic_file_download_white_24dp); floatingActionButton .getMainFab() .setOnClickListener( v -> { if (uris != null && uris.size() > 0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { File folder = new File(getCurrentMainFragment().getCurrentPath()); int result = mainActivityHelper.checkFolder(folder, MainActivity.this); if (result == MainActivityHelper.WRITABLE_OR_ON_SDCARD) { FileUtil.writeUriToStorage( MainActivity.this, uris, getContentResolver(), getCurrentMainFragment().getCurrentPath()); finish(); } else { operation = DataUtils.SAVE_FILE; urisToBeSaved = uris; mainActivityHelper.checkFolder(folder, MainActivity.this); } } else { FileUtil.writeUriToStorage( MainActivity.this, uris, getContentResolver(), getCurrentMainFragment().getCurrentPath()); Toast.makeText( MainActivity.this, getResources().getString(R.string.saving), Toast.LENGTH_LONG) .show(); finish(); } } else { Bundle extras = intent.getExtras(); String data = extras.getString(Intent.EXTRA_SUBJECT) + "\nURL: " + extras.getString(Intent.EXTRA_TEXT); String fileName = Long.toString(System.currentTimeMillis()); <START> FileUtil.mktextfile(data, getCurrentMainFragment().getCurrentPath(), fileName); <END> Toast.makeText( MainActivity.this, getResources().getString(R.string.saving) + " to " + getCurrentMainFragment().getCurrentPath(), Toast.LENGTH_LONG) .show(); finish(); } }); floatingActionButton.setVisibility(View.VISIBLE); }</code><technical_language>If notice, call is sync, saving data occurs in main thread, is recommended. Please write this call in runnable follows. AppConfig.runInBackground(() -> FileUtil.mktextfile(data, getCurrentMainFragment().getCurrentPath(), fileName));</technical_language>

Target:
private void initFabToSave(final ArrayList<Uri> uris) { clearFabActionItems(); floatingActionButton.getMainFab().setImageResource(R.drawable.ic_file_download_white_24dp); floatingActionButton .getMainFab() .setOnClickListener( v -> { if (uris != null && uris.size() > 0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { File folder = new File(getCurrentMainFragment().getCurrentPath()); int result = mainActivityHelper.checkFolder(folder, MainActivity.this); if (result == MainActivityHelper.WRITABLE_OR_ON_SDCARD) { FileUtil.writeUriToStorage( MainActivity.this, uris, getContentResolver(), getCurrentMainFragment().getCurrentPath()); finish(); } else { operation = DataUtils.SAVE_FILE; urisToBeSaved = uris; mainActivityHelper.checkFolder(folder, MainActivity.this); } } else { FileUtil.writeUriToStorage( MainActivity.this, uris, getContentResolver(), getCurrentMainFragment().getCurrentPath()); Toast.makeText( MainActivity.this, getResources().getString(R.string.saving), Toast.LENGTH_LONG) .show(); finish(); } } else { Bundle extras = intent.getExtras(); String data = extras.getString(Intent.EXTRA_SUBJECT) + "\nURL: " + extras.getString(Intent.EXTRA_TEXT); String fileName = Long.toString(System.currentTimeMillis()); AppConfig.runInBackground( () -> FileUtil.mktextfile( data, getCurrentMainFragment().getCurrentPath(), fileName)); Toast.makeText( MainActivity.this, getResources().getString(R.string.saving) + " to " + getCurrentMainFragment().getCurrentPath(), Toast.LENGTH_LONG) .show(); finish(); } }); floatingActionButton.setVisibility(View.VISIBLE); }