从Adobe AIR扩展

时间:2015-11-29 06:39:47

标签: android air urbanairship.com ane

我正在为Urban Airship创建一个ANE,这是一种发送推送通知的服务(除此之外)。到目前为止,集成工作得很好,但只有在应用程序开放时才能实现。退出应用程序后,收到新的推送通知会导致应用程序崩溃:

11-29 01:19:32.448 22340-22340/air.com.example.app E/Urban Airship Autopilot: Unable to takeOff automatically
11-29 01:19:32.496 22340-22440/air.com.example.app E/AndroidRuntime: FATAL EXCEPTION: IntentService[PushService]
                                                                                  Process: air.com.example.app, PID: 22340
                                                                                  java.lang.IllegalStateException: Take off must be called before shared()
                                                                                      at com.urbanairship.UAirship.shared(UAirship.java:147)
                                                                                      at com.urbanairship.BaseIntentService.onHandleIntent(BaseIntentService.java:94)
                                                                                      at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java)
                                                                                      at android.os.Looper.loop(Looper.java)
                                                                                      at android.os.HandlerThread.run(HandlerThread.java)

通过大量的挖掘,我认为问题是我从TakeoffFunction(我的ANE中的FREFunction)中调用UAirship.takeOff()而不是从Application的主onCreate方法调用它(就像在:UrbanAirship NPE

这是我的TakeoffFunction:

public class TakeoffFunction implements FREFunction
{
    @Override
    public FREObject call(FREContext context, FREObject[] freObjects)
    {
         Log.d("TakeoffFunction", "Attempting Urban Airship TAKEOFF");

        Application app = context.getActivity().getApplication();

        Log.d("TakeoffFunction", "app found: " + app);

        AirshipConfigOptions options = new AirshipConfigOptions();
        options.developmentAppKey = "xxx";
        options.developmentAppSecret = "xxx";
        options.inProduction = false;
        options.gcmSender = "000";


        Log.d("TakeoffFunction", "Prepare to Launch...");
        UAirship.takeOff(app, options, new UAirship.OnReadyCallback()
        {
            @Override
            public void onAirshipReady(UAirship uAirship)
            {
                Log.d("TakeoffFunction", "Urban Airship is ready after takeoff");
                uAirship.getPushManager().setUserNotificationsEnabled(true);
                Log.d("TakeoffFunction", "User notifications have been enabled");
            }
        });
        return null;
    }
}

因此,似乎我需要以某种方式从主应用程序的onCreate方法调用UAirship.takeOff()。然而,这被证明是一个挑战,因为我知道对于Adobe AIR,有一个AppEntry类作为主要的Application类,但据我所知,这个类被禁止修改开发人员。我发现本教程:http://blogs.adobe.com/digitalmedia/2011/05/extending-air-for-android/从2011年开始,然后才正式支持原生扩展。在那里我看到他们能够覆盖和扩展onCreate()方法,但我不知道如何使用这个原生扩展来做同样的事情。

我想知道是否可以扩展AppEntry的onCreate方法或将AIR指向另一个AppEntry类,覆盖原始类。

1 个答案:

答案 0 :(得分:1)

通常看到libs希望让应用程序在创建所有服务,接收器或活动之前,在应用程序的onCreate中初始化其模块。基本上是所有应用程序的唯一真正入口点。

对于Adobe这样难以在应用程序文件中调用起飞的框架,我们添加了另一种使用Autopilot调用起飞的方法。

示例:

public class AirAutopilot extends Autopilot {
    @Override
    public AirshipConfigOptions createAirshipConfigOptions(Context context) {
        AirshipConfigOptions options = new AirshipConfigOptions();
        options.developmentAppKey = "xxx";
        options.developmentAppSecret = "xxx";
        options.inProduction = false;
        options.gcmSender = "000";

        return options;
    }

    @Override
    public void onAirshipReady(UAirship airship) {
        Log.d("TakeoffFunction", "Urban Airship is ready after takeoff");
        airship.getPushManager().setUserNotificationsEnabled(true);
        Log.d("TakeoffFunction", "User notifications have been enabled");
    }
}

然后将autopilot类添加到应用程序块中的清单(不确定Adobe Air的方式):

<meta-data android:name="com.urbanairship.autopilot" android:value="com.example.AirAutopilot" />

然后在您的插件中,确保在访问UAirship实例之前调用自动驾驶:

Autopilot.automaticTakeOff(context.getActivity().getApplication());