Question

I am writing an extension that will allow a Flex application to access Android's native image picker. I am able to launch the image picker activity without issue, but after it returns to the caller, which is an FREFunction object, onActivityResult is not called. Because of this, I am unable to figure out what image the user has chosen.

When I use the exact same contents of the FREFunction in a native Android app, The app works fine, and I am able to retrieve the URI of the chosen image in onActivityResult. How can I get onActivityResult to fire, or at least retrieve the information returned by the image picker activity?

Was it helpful?

Solution

Another, simpler solution:

  • In ANE extension's native java project, include runtimeClasses.jar from AIR's lib folder (AIR\lib\android\lib), along with FlashRuntimeExtension.jar. This gives you access to AIR's AndroidActivityWrapper class.

  • Since some interfaces in runtimeClasses.jar are defined as protected, you need to make them accessible to your extension. So, create two interfaces in com.adobe.air package namespace:


ActivityResultCallback.java

package com.adobe.air;

import com.adobe.air.AndroidActivityWrapper;

public abstract interface ActivityResultCallback extends AndroidActivityWrapper.ActivityResultCallback
{
}

StateChangeCallback.java

package com.adobe.air;

import com.adobe.air.AndroidActivityWrapper;

public abstract interface StateChangeCallback extends AndroidActivityWrapper.StateChangeCallback
{
}
  • You can now register some callbacks in our extension:

ExtensionContext.java

package com.company.extension;

import java.util.HashMap;
import java.util.Map;
import android.content.Intent;
import android.content.res.Configuration;
import com.adobe.air.ActivityResultCallback;
import com.adobe.air.AndroidActivityWrapper;
import com.adobe.air.AndroidActivityWrapper.ActivityState;
import com.adobe.air.StateChangeCallback;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;

public class ExtensionContext extends FREContext implements ActivityResultCallback, StateChangeCallback
{
    private AndroidActivityWrapper aaw;

    public ExtensionContext() {
        aaw = AndroidActivityWrapper.GetAndroidActivityWrapper();
        aaw.addActivityResultListener( this );
        aaw.addActivityStateChangeListner( this );
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent ) {
    }

    @Override 
    public void onActivityStateChanged( ActivityState state ) {
        switch ( state ) {
            case STARTED:
            case RESTARTED:
            case RESUMED:
            case PAUSED:
            case STOPPED:
            case DESTROYED:
        }
    }

    @Override
    public void onConfigurationChanged(Configuration paramConfiguration)
    {
    }

    @Override
    public Map<String, FREFunction> getFunctions() {
        Map<String, FREFunction> functionMap = new HashMap<String, FREFunction>();
        return functionMap; 
    }

    @Override 
    public void dispose() { 
        if (aaw!=null) {
            aaw.removeActivityResultListener( this );
            aaw.removeActivityStateChangeListner( this );
            aaw = null;
        }
    } 
}

OTHER TIPS

The solution is to start an activity from the FREFunction, and then use that activity's onActivityResult function to perform the desired actions that would require the returning activity's data.

From there, you can use StatusEvent to send information back to your Flex application. Make sure to have listeners for StatusEvent, and proper functions to handle the data based on the event's label.

Note: Adding extras to the activity that is to run your onActivityResult may cause the activity to never be called. Instead, create public static fields in your FREFunction for the activity to call.

In addition, ensure that the context being used in the activity is the FREContext used by the native extension handler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top