挂钩到从Adobe AIR扩展主应用程序的onCreate方法 [英] Hooking into main application's onCreate method from Adobe AIR extension

查看:445
本文介绍了挂钩到从Adobe AIR扩展主应用程序的onCreate方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造城市飞艇,用于发送推送通知服务的ANE(除其他事项外)。到目前为止,一体化的工作很好,但只有当应用程序是开放的。当应用程序退出时,接收应用了新的推送通知结果与崩溃:

I am creating an ANE for Urban Airship, a service for sending push notifications (among other things). So far the integration has worked great but only when the app is open. When the app is exited, receiving a new push notification results in the app crashing with:

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()而不是从应用程序的主onCreate方法调用(即是中看到的问题: UrbanAirship NPE

下面是我的TakeoffFunction:

Here is my 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类,其功能作为主应用程序类,但这个类是,据我所知,从修改禁止开发者使用。我发现这个教程: http://blogs.adobe.com /的DigitalMedia / 2011/05 /延长空气换的Andr​​oid / 从早在2011年之前的原生扩展正式支持。在那里,我看到他们能够覆盖和延伸onCreate()方法,但我不知道我怎么会去这个原生扩展做同样的事情。

Thus, it would seem I need to somehow call UAirship.takeOff() from the main application's onCreate method. However, this is proving to be a challenge as I know that for Adobe AIR, there is an AppEntry class which functions as the main Application class, but this class is, as far as I know, barred from modification for developers. I found this tutorial: http://blogs.adobe.com/digitalmedia/2011/05/extending-air-for-android/ from back in 2011 before native extensions were officially supported. In there I see that they're able to override and extend the onCreate() method, but I don't know how I would go about doing the same thing with this native extension.

我想知道是否有可能给AppEntry的onCreate方法或点AIR完全扩展到不同的AppEntry类,覆盖原来的。

I would like to know if it is possible to extend the AppEntry's onCreate method or point AIR to a different AppEntry class altogether, overwriting the original.

推荐答案

它经常可以看到希望了该应用程序初始化其模块中的应用程序的onCreate作为其库中创建的所有服务,接收器或活动之前被调用。基本上是唯一的真正切入点所有的应用程序。

Its common to see libs wanting to have the app initialize its module in the application's onCreate as its called before all services, receivers, or activities are created. Basically the only real entry point for all apps.

有关其中的应用程序了文件其很难称之为起飞,我们增加了使用电话起飞的另一种方式<一个像Adobe的框架href=\"http://docs.urbanairship.com/reference/libraries/android/latest/reference/com/urbanairship/Autopilot.html\"相对=nofollow>自动驾驶仪。

For frameworks like Adobe where its hard to call takeoff in the applicaiton file, we have added another way of calling takeoff using 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");
    }
}

然后自动驾驶类添加到清单中的应用程序块(不知道这样做的Adobe AIR的方式):

Then add the autopilot class to the manifest in the application block (not sure about the Adobe Air way of doing this):

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

然后在你的插件,确保调用自动驾驶仪访问UAirship实例之前即发:

Then in your plugin, make sure a call to autopilot is made before accessing the UAirship instance:

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

这篇关于挂钩到从Adobe AIR扩展主应用程序的onCreate方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆