Skip to main content

Background Export

A quick guide on how to enable the background export feature in VideoEditor SDK for Android.

This document guides you through the process of enabling the VideoEditor SDK background exporting.

Implement background export capability#

If you want to export in the background the onActivityResult() method will not longer work. Instead you have to use a BroadcastReceiver to receive your exported data.

Create a BroadcastReceiver#

In order to enable the editor to pass the resulting file to you in an asynchronous way, you have to create a BroadcastReceiver class like in this example.

class EditorResultReceiverKotlin : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val data = EditorSDKResult(intent)

        when (data.resultStatus) {
            EditorSDKResult.Status.CANCELED -> {
                Toast.makeText(context, "Editor is closed because the User clicks the cancel button.", Toast.LENGTH_LONG).show()
            EditorSDKResult.Status.CANCELED_BY_SYSTEM -> {
                 * The editor is canceled by the System, because of unknown reason. *
                 * The User has maybe force closed the App                          *
            EditorSDKResult.Status.DONE_WITHOUT_EXPORT -> {
                Toast.makeText(context, "Editor result accepted but not changed.", Toast.LENGTH_LONG).show()
            EditorSDKResult.Status.EXPORT_STARTED -> {
                // The editor has started the export, we can now save the serialization in the meantime.
                File(Environment.getExternalStorageDirectory(), "SavedEditorState.json").also {
                }.outputStream().use {
            EditorSDKResult.Status.EXPORT_DONE -> {
                // The editor export is done, we can now save the image and notify the gallery to update the image.
                data.notifyGallery(to = EditorSDKResult.UPDATE_RESULT and EditorSDKResult.UPDATE_SOURCE)
                Toast.makeText(PESDK.getAppContext(), "Editor Export is done. File is saved at: ${data.resultUri}.", Toast.LENGTH_LONG).show()

Update your AndroidManifest.xml#

Open your Application Manifest and add the BroadcastReceiver and a permission.

ATTENTION!!! You have to name my.own.package.RECEIVE_RESULT_PERMISSION with you own permission name, for example use "your.package.RECEIVE_RESULT_PERMISSION" instead of "my.own.package.RECEIVE_RESULT_PERMISSION".

If another App with the same permission name is installed, the installation of your App will be blocked.

<manifest xmlns:android="" package="my.own.package" >
    <!-- It is important to have your own permission name in the next two lines here-->
    <uses-permission android:name="my.own.package.RECEIVE_RESULT_PERMISSION" />
    <permission android:protectionLevel="signature" android:name="my.own.package.RECEIVE_RESULT_PERMISSION" />
    <application your_paramters="...">
        <!-- Insert your permission name into android:permission="..." -->
                <!-- It is important to have your own action name here -->
                <action android:name="my.fancy.BroadcastReceiverAction" />


Update your build.gradle and include the headless module.#

This will add the RenderService and some app permission we need for the background export.

imglyConfig {
    modules {
        include 'backend:headless'

Start the editor with startActivityForBroadcast instead of startActivityForResult#

Now instead of starting with startActivityForResult we use startActivityForBroadcast and pass the BroadcastReceiver action name as the second parameter.

class KVideoEditorDemoActivityAsync : Activity(), PermissionRequest.Response {

    companion object {
        const val VESDK_RESULT_BROADCAST_RECEIVER = "my.fancy.BroadcastReceiverAction"
        const val GALLERY_RESULT = 2

    // Important permission request for Android 6.0 and above, don't forget to add this!
    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
        PermissionRequest.onRequestPermissionsResult(requestCode, permissions, grantResults)
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)

    override fun permissionGranted() {}

    override fun permissionDenied() {
        /* TODO: The Permission was rejected by the user. The Editor was not opened,
         * Show a hint to the user and try again. */

    // Create an empty new SettingsList and apply the changes on this reference.
    // If you include our asset Packs and use our UI you also need to add them to the UI,
    // otherwise they are only available for the backend (like Serialization)
    // See the specific feature sections of our guides if you want to know how to add your own Assets.
    private fun createVesdkSettingsList() =
        .configure<UiConfigFilter> {
        .configure<UiConfigText> {
        .configure<UiConfigFrame> {
        .configure<UiConfigOverlay> {
        .configure<UiConfigSticker> {

    override fun onCreate(savedInstanceState: Bundle?) {


    fun openSystemGalleryToSelectAnVideo() {
        val intent = Intent(Intent.ACTION_PICK)

        if (intent.resolveActivity(packageManager) != null) {
            startActivityForResult(intent, GALLERY_RESULT)
        } else {
              "No Gallery app installed",

    fun openEditor(inputSource: Uri?) {
        val settingsList = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        } else {
            Toast.makeText(this, "Video support needs Android 4.3", Toast.LENGTH_LONG).show()

        settingsList.configure<LoadSettings> {
            it.source = inputSource

        settingsList[LoadSettings::class].source = inputSource

          .startActivityForBroadcast(this, VESDK_RESULT_BROADCAST_RECEIVER)

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (resultCode == RESULT_OK && requestCode == GALLERY_RESULT) {
            // Open Editor with some uri in this case with an video selected from the system gallery.