另一个更简单的解决方案:
在 ANE 扩展的原生 java 项目中,包括
来自 AIR 的 lib 文件夹 ( AIR\lib\android\lib ) 的runtimeClasses.jar以及FlashRuntimeExtension.jar。这使您可以访问 AIR 的 AndroidActivityWrapper 类。
由于runtimeClasses.jar中的某些接口被定义为受保护的,因此您需要使它们可以被您的扩展访问。因此,在 com.adobe.air 包命名空间中创建两个接口:
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
{
}
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;
}
}
}