To Gallery
Start Editor#
For the sake of this example, we load a photo from the resources into the photo editor.
Configure the PhotoEditorSaveSettings
to save the exported photo to the gallery using the setOutputToGallery()
method. This saves the photo in Environment.DIRECTORY_DCIM
.
You can also specify the folder name and file name by calling setOutputToGallery(folder, name)
instead. If scoped storage is enabled, DCIM
and Pictures
are the only two valid folder names. The name of the file can contain a SimpleDateFormat
pattern inside angular brackets like img_<yyMMddHHmmss>
. This would be evaluated at the time of export.
Handle Result#
The result from the editor is received in the onActivityResult()
method. EditorSDKResult
wraps around the intent and provides a convenient API to check the result. The Uri
of the exported photo can be accessed via EditorSDKResult.resultUri
.
class SavePhotoToGallery(private val activity: AppCompatActivity) : Example(activity) {override fun invoke() {// In this example, we do not need access to the Uri(s) after the editor is closed// so we pass false in the constructorval settingsList = PhotoEditorSettingsList(false)// Set the source as the Uri of the image to be loaded.configure<LoadSettings> {it.source = activity.resourceUri(R.drawable.la)}// Save output to Gallery.configure<PhotoEditorSaveSettings> {it.setOutputToGallery()}// Start the photo editor using PhotoEditorBuilder// The result will be obtained in onActivityResult() corresponding to EDITOR_REQUEST_CODEPhotoEditorBuilder(activity).setSettingsList(settingsList).startActivityForResult(activity, EDITOR_REQUEST_CODE)// Release the SettingsList once donesettingsList.release()}override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {super.onActivityResult(requestCode, resultCode, intent)intent ?: returnif (requestCode == EDITOR_REQUEST_CODE) {val result = EditorSDKResult(intent)when (result.resultStatus) {EditorSDKResult.Status.CANCELED -> showMessage("Editor cancelled")EditorSDKResult.Status.EXPORT_DONE -> showMessage("Result saved at ${result.resultUri}")else -> {}}}}}