2013-02-13 74 views
4

我有一个android应用程序成功设置为使用Urban Airship接收通知,但遇到处理PushManager.ACTION_NOTIFICATION_OPENED)广播时出现问题。我的广播接收器工作时,接收消息,并调用以下(从示例代码):当用户点击Urban Airship通知时重新启动android应用程序

Intent launch = new Intent(Intent.ACTION_MAIN); 
launch.setClass(UAirship.shared().getApplicationContext(), Main.class); 
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
UAirship.shared().getApplicationContext().startActivity(launch); 

这工作得很好,带来的主要活动带回到前台,除了其中的应用程序是没有的情况下长时间运行。如果我发送通知到手机,杀应用程序,然后打开通知,上一个NullPointerException异常应用程序崩溃:

Failed to load meta-data, NullPointer: null 
Unable to takeOff automatically 
FATAL EXCEPTION: main 
java.lang.RuntimeException: Unable to start receiver com.urbanairship.CoreReceiver:   java.lang.NullPointerException 
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2236) 
at android.app.ActivityThread.access$1500(ActivityThread.java:130) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4745) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 

我想不出什么可能会导致此。有什么想法吗?

回答

3

好的,算出来了。

我正在实例化UrbanAirship并从Activity上下文注册IntentReceiver,而不是从Application上下文注册。

糟糕。

+1

可以共享代码,我也越来越相同的问题?请帮助我@TomBomb。 – 2014-02-10 15:11:21

1

我遇到了同样的问题。我通过将UAirship初始化放入应用程序的onCreate而非Activity来解决它。

嗨阿米特Jayaswal,请参阅如下例子:

公共类MyApplication的扩展应用{

@Override 
public void onCreate() { 
    super.onCreate(); 

    // Optionally, customize your config at runtime: 
    // 
    // AirshipConfigOptions options = new AirshipConfigOptions(); 
    // options.inProduction = false; 
    // options.developmentAppKey = "Your Development App Key"; 
    // options.developmentAppSecret "Your Development App Secret"; 
    // 
    // UAirship.takeOff(this, options); 

    UAirship.takeOff(this, new UAirship.OnReadyCallback() { 
     @Override 
     public void onAirshipReady(UAirship airship) { 
      // Perform any airship configurations here 

      // Create a customized default notification factory 
      DefaultNotificationFactory defaultNotificationFactory = new DefaultNotificationFactory(getApplicationContext()); 
      defaultNotificationFactory.setSmallIconId(R.drawable.ic_notification); 
      //defaultNotificationFactory.setColor(NotificationCompat.COLOR_DEFAULT); 

      // Set it 
      airship.getPushManager().setNotificationFactory(defaultNotificationFactory); 

      // Enable Push 
      airship.getPushManager().setPushEnabled(true); 
     } 
    }); 
} 

}

相关问题