【发布时间】:2016-03-02 23:59:43
【问题描述】:
我正在为 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(),而不是从应用程序的主要 onCreate 方法调用它(正如在:UrbanAirship NPE)
这是我的起飞函数:
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/extending-air-for-android/,早在 2011 年就开始正式支持原生扩展。在那里我看到他们能够覆盖和扩展 onCreate() 方法,但我不知道如何使用这个原生扩展做同样的事情。
我想知道是否可以扩展 AppEntry 的 onCreate 方法或将 AIR 完全指向不同的 AppEntry 类,覆盖原来的。
【问题讨论】:
标签: android air urbanairship.com ane