Adobe Creative SDK

Follow

Android - Image Editor: AviaryIntent Builder workaround for Android APIs 14 and 15

 In v0.9.x and up, the minimum Android API is 16. APIs 14 and 15 are no longer supported.


 

Overview

There is a known issue where the AviaryIntent.Builder class does not work for Android APIs 14 and 15.

This article will show you a workaround for this issue.

Check the API version

First, have your app check if the Android API being used is at least 16 or greater, using the APIHelper class:

/* AviaryIntent.Builder supports API 16 and up */
if (ApiHelper.AT_LEAST_16) {

    Intent imageEditorIntent = new AviaryIntent.Builder(this)
            .setData(uri) /* input image src */
            .withOutput(Uri.parse(getFilesDir() + "/image1.jpg")) /* output file */
            .withOutputFormat(Bitmap.CompressFormat.JPEG) /* output format */
            .withOutputSize(MegaPixels.Mp5) /* output size */
            .withOutputQuality(90) /* output quality */
            .withToolList(mTools) /* custom tool list */
            .build();

    /* start the activity */
    startActivityForResult(imageEditorIntent, 1);
}

Mimic the AviaryIntent.Builder methods for APIs 14 and 15

Next, in the else block, you will need to:

  1. create a new intent, passing in FeatherActivity.class.
  2. call the intent’s setData() method
  3. mimic the AviaryIntent.Builder methods
  4. start the activity

Here is an example that corresponds to the AviaryIntent.Builder code above:

else {
    /* 1) Create the intent */
    Intent anotherIntent = new Intent(this, FeatherActivity.class);

    /* 2) Call setData() */
    anotherIntent.setData(uri);
    
    /* 3) Mimic the AviaryIntent.Builder methods */
    anotherIntent.putExtra(Constants.EXTRA_OUTPUT, getFilesDir() + "/image1.jpg");
    anotherIntent.putExtra(Constants.EXTRA_OUTPUT_FORMAT, Bitmap.CompressFormat.JPEG);
    anotherIntent.putExtra(Constants.EXTRA_IN_HIRES_MEGAPIXELS, MegaPixels.Mp5);
    anotherIntent.putExtra(Constants.EXTRA_OUTPUT_QUALITY, 90);

    String[] array = new String[mTools.length];

    for(int i = 0; i < mTools.length; ++i) {
        array[i] = mTools[i].name();
    }
    anotherIntent.putExtra(Constants.EXTRA_TOOLS_LIST, array);

    /* 4) Start the activity */
    startActivityForResult(anotherIntent, 1);

}

Find the AviaryIntent.Builder methods in the source

You can find the AviaryIntent.Builder methods in:

/com/aviary/android/feather/sdk/AviaryIntent.class

Or by Command/Control-clicking on the AviaryIntent.Builder class name in Android Studio.

Sample code

private void launchEditor() {
    Uri uri = Uri.parse("http://mysite.com/image.jpeg");
    ToolLoaderFactory.Tools[] tools = {ToolLoaderFactory.Tools.CROP};

    /* AviaryIntent supports API 16 and up */
    if (ApiHelper.AT_LEAST_16) {

        Intent imageEditorIntent = new AviaryIntent.Builder(this)
                .setData(uri)
                .withOutput(Uri.parse(getFilesDir() + "/image1.jpg")
                .withOutputFormat(Bitmap.CompressFormat.JPEG)
                .withOutputSize(MegaPixels.Mp5)
                .withOutputQuality(90)
                .withToolList(tools)
                .build();

        startActivityForResult(imageEditorIntent, 1);
    }
    else {
        /* 1) Create the intent */
        Intent anotherIntent = new Intent(this, FeatherActivity.class);

        /* 2) Call setData() */
        anotherIntent.setData(uri);

        /* 3) Mimic the AviaryIntent.Builder methods */
        anotherIntent.putExtra(Constants.EXTRA_OUTPUT, getFilesDir() + "/image1.jpg");
        anotherIntent.putExtra(Constants.EXTRA_OUTPUT_FORMAT, Bitmap.CompressFormat.JPEG);
        anotherIntent.putExtra(Constants.EXTRA_IN_HIRES_MEGAPIXELS, MegaPixels.Mp5);
        anotherIntent.putExtra(Constants.EXTRA_OUTPUT_QUALITY, 90);

        String[] array = new String[tools.length];

        for(int i = 0; i < tools.length; ++i) {
            array[i] = tools[i].name();
        }
        anotherIntent.putExtra(Constants.EXTRA_TOOLS_LIST, array);

        /* 4) Start the activity */
        startActivityForResult(anotherIntent, 1);
    }
}
Was this article helpful?
0 out of 0 found this helpful

Comments

Powered by Zendesk