Autopilot和java.lang.RuntimeException:无法启动接收器com.urbanairship.push.GCMPushReceiver:java.lang.NullPointerException

时间:2014-08-21 13:48:57

标签: java android push-notification urbanairship.com air-native-extension

我正在尝试使用UrbanAirship library urbanairship-lib-4.0.4.jar为Angroid创建Adobe Air原生扩展。

一切正常,直到我将选项配置(AppKey,AppSecret等)从主应用程序类移动到autopilot类。根据{{​​3}}自动驾驶仪推迟takeOff,这正是我需要在初始化原生扩展后调用takeOff并为UrbanAirship设置所有需要的选项。一切正常,但我必须等待更长时间才能获得第一个PN(我猜这是使用自动驾驶仪的后果)。当应用程序从最近的应用程序屏幕上擦除(不在后台运行)然后PN来时,问题就开始了:

08-21 19:20:16.019: I/GCM(15483): GCM message air.xx.xxxx.testPushNotifications 0:1408620017436060%0#b0e5f2beea92a435
08-21 19:20:16.039: I/ActivityManager(594): Start proc air.xx.xxxx.testPushNotifications for broadcast air.xx.xxxx.testPushNotifications/com.urbanairship.push.GCMPushReceiver: pid=5483 uid=10138 gids={50138, 3003}
08-21 19:20:16.089: I/MyAutoPilot(5483): Settings initialization
08-21 19:20:16.209: D/AndroidRuntime(5483): Shutting down VM
08-21 19:20:16.209: W/dalvikvm(5483): threadid=1: thread exiting with uncaught exception (group=0x41588ba8)
08-21 19:20:16.209: W/GCM-DMM(15483): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=air.xx.xxxx.testPushNotifications (has extras) }
08-21 19:20:16.209: E/AndroidRuntime(5483): FATAL EXCEPTION: main
08-21 19:20:16.209: E/AndroidRuntime(5483): Process: air.xx.xxxx.testPushNotifications, PID: 5483
08-21 19:20:16.209: E/AndroidRuntime(5483): java.lang.RuntimeException: Unable to start receiver com.urbanairship.push.GCMPushReceiver: java.lang.NullPointerException
08-21 19:20:16.209: E/AndroidRuntime(5483):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2426)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at android.app.ActivityThread.access$1700(ActivityThread.java:135)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at android.os.Handler.dispatchMessage(Handler.java:102)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at android.os.Looper.loop(Looper.java:136)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at android.app.ActivityThread.main(ActivityThread.java:5017)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at java.lang.reflect.Method.invokeNative(Native Method)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at java.lang.reflect.Method.invoke(Method.java:515)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at dalvik.system.NativeStart.main(Native Method)
08-21 19:20:16.209: E/AndroidRuntime(5483): Caused by: java.lang.NullPointerException
08-21 19:20:16.209: E/AndroidRuntime(5483):     at xx.xxxx.PushNotificationsUrbanAirship.MyAutoPilot.execute(MyAutoPilot.java:47)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at com.urbanairship.Autopilot.automaticTakeOff(Autopilot.java:110)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at com.urbanairship.push.GCMPushReceiver.onReceive(GCMPushReceiver.java:53)
08-21 19:20:16.209: E/AndroidRuntime(5483):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2419)
08-21 19:20:16.209: E/AndroidRuntime(5483):     ... 10 more

然后......

08-21 19:20:24.608: I/ActivityManager(594): Process air.xx.xxxx.testPushNotifications (pid 5483) has died.
08-21 19:21:06.092: I/ActivityManager(594): Start proc air.xx.xxxx.testPushNotifications for service air.xx.xxxx.testPushNotifications/com.urbanairship.analytics.EventService: pid=5536 uid=10138 gids={50138, 3003}
08-21 19:21:06.172: I/MyAutoPilot(5536): Settings initialization
08-21 19:21:06.282: D/AndroidRuntime(5536): Shutting down VM
08-21 19:21:06.282: W/dalvikvm(5536): threadid=1: thread exiting with uncaught exception (group=0x41588ba8)
08-21 19:21:06.282: E/AndroidRuntime(5536): FATAL EXCEPTION: main
08-21 19:21:06.282: E/AndroidRuntime(5536): Process: air.xx.xxxx.testPushNotifications, PID: 5536
08-21 19:21:06.282: E/AndroidRuntime(5536): java.lang.RuntimeException: Unable to create service com.urbanairship.analytics.EventService: java.lang.NullPointerException
08-21 19:21:06.282: E/AndroidRuntime(5536):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2582)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at android.app.ActivityThread.access$1800(ActivityThread.java:135)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at android.os.Handler.dispatchMessage(Handler.java:102)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at android.os.Looper.loop(Looper.java:136)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at android.app.ActivityThread.main(ActivityThread.java:5017)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at java.lang.reflect.Method.invokeNative(Native Method)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at java.lang.reflect.Method.invoke(Method.java:515)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at dalvik.system.NativeStart.main(Native Method)
08-21 19:21:06.282: E/AndroidRuntime(5536): Caused by: java.lang.NullPointerException
08-21 19:21:06.282: E/AndroidRuntime(5536):     at tv.mhub.PushNotificationsUrbanAirship.MyAutoPilot.execute(MyAutoPilot.java:47)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at com.urbanairship.Autopilot.automaticTakeOff(Autopilot.java:110)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at com.urbanairship.analytics.EventService.onCreate(EventService.java:94)
08-21 19:21:06.282: E/AndroidRuntime(5536):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2572)
08-21 19:21:06.282: E/AndroidRuntime(5536):     ... 10 more

ApplicationManifest包括:

<application android:enabled="true">
<meta-data android:name="com.urbanairship.autopilot" android:value="xx.xxxx.PushNotificationsUrbanAirship.MyAutoPilot" />           



<!-- Needed for Action.startActivityForResult -->
<activity android:name="com.urbanairship.actions.ActionActivity"/>



<!-- MODIFICATION REQUIRED
- Set or Remove the parent activity
- For more customization details, see com.urbanairship.actions.LandingPageActivity -->
<activity
       android:name="com.urbanairship.actions.LandingPageActivity"
       android:parentActivityName="xx.xxxx.PushNotificationsUrbanAirship.MainActivity"
       android:exported="false">

      <meta-data
           android:name="android.support.PARENT_ACTIVITY"
           android:value="xx.xxxx.PushNotificationsUrbanAirship.MainActivity" />

      <intent-filter>
           <action ndroid:name="com.urbanairship.actions.SHOW_LANDING_PAGE_INTENT_ACTION"/>
           <data android:scheme="http" />
           <data android:scheme="https" />
           <category android:name="android.intent.category.DEFAULT"/>
      </intent-filter>
</activity>



<!-- REQUIRED for Urban Airship GCM-->
<receiver android:name="com.urbanairship.CoreReceiver" />
<receiver android:name="com.urbanairship.push.GCMPushReceiver"   
            android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

        <!-- MODIFICATION REQUIRED - Use your package name as the category -->
            <category android:name="air.xx.xxxx.testPushNotifications" />
        </intent-filter>

        <!--  REQUIRED for detecting when the application is upgraded so it can request a new GCM ID -->
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
            <data android:scheme="package"/>
        </intent-filter>
</receiver>



<service android:name="com.urbanairship.push.PushService" android:label="Push Notification Service"/>
<service android:name="com.urbanairship.analytics.EventService" android:label="Event Service"/>
<service android:name="com.urbanairship.actions.ActionService" />



<!-- This is required for persisting preferences related to push and location -->
<!-- MODIFICATION REQUIRED - Replace "com.urbanairship.push.sample" with your package name -->
<provider android:name="com.urbanairship.UrbanAirshipProvider"

 android:authorities="air.xx.xxxx.testPushNotifications.urbanairship.provider"

 android:permission="air.xx.xxxx.testPushNotifications.permission.UA_DATA"
                                      android:exported="true"
                                      android:multiprocess="true" />
 <!-- END OF REQUIRED ITEMS -->


 <!-- OPTIONAL (for segments support) -->
 <service android:name="com.urbanairship.location.LocationService" android:label="Segments Service"/>

 <!-- OPTIONAL, if you want to receive push, push opened and registration completed intents -->
 <!-- Replace the receiver below with your package and class name -->
 <receiver android:name="xx.xxxx.PushNotificationsUrbanAirship.IntentReceiver" />

</application>

申请类:

package xx.xxxx.PushNotificationsUrbanAirship;

import android.app.Application;

public class MyApplication extends Application {

    @Override
    public void onCreate() {

        super.onCreate();

    }
}

MainActivity:

package xx.xxxx.PushNotificationsUrbanAirship;

import android.os.Bundle;

import com.urbanairship.analytics.InstrumentedActivity;

public class MainActivity extends InstrumentedActivity {


    @Override
    public void onCreate(Bundle savedInstanceState) {

    }
}

自动驾驶仪:

package xx.xxxx.PushNotificationsUrbanAirship;

import android.app.Application;
import android.util.Log;

import com.urbanairship.AirshipConfigOptions;
import com.urbanairship.Autopilot;
import com.urbanairship.UAirship;
import com.urbanairship.push.PushManager;

public class MyAutoPilot extends Autopilot {

    private static final String TAG = "MyAutoPilot";

    private String _appKey;
    private String _appSecret;
    private String _gcmSender;
    private Boolean _inProduction;

    public void setAppKey(String appKey){
        Log.i(TAG, "Setting appKey");
        _appKey = appKey;
    }

    public void setAppSecret(String appSecret){
        Log.i(TAG, "Setting appSecret");
        _appSecret = appSecret;
    }

    public void setGcmSender(String gcmSender){
        Log.i(TAG, "Setting gcmSender");
        _gcmSender = gcmSender;
    }

    public void setInProduction(Boolean inProduction){
        Log.i(TAG, "Setting inProduction");
        _inProduction = inProduction;
    }

    @Override
    public void execute(Application application) {

        Log.i(TAG, "Settings initialization");

        AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(application);

        if(_inProduction) {
            options.productionAppKey = _appKey;
            options.productionAppSecret = _appSecret;
        }
        else {
            options.developmentAppKey = _appKey;
            options.developmentAppSecret = _appSecret;
        }

        options.inProduction = _inProduction;
        options.transport = "gcm";
        options.gcmSender = _gcmSender;

        UAirship.takeOff(application, options);

        PushManager.enablePush();

        PushManager.shared().setIntentReceiver(IntentReceiver.class);
    }

}

FREFunction:

package xx.xxxx.PushNotificationsUrbanAirship.functions;

import xx.xxxx.PushNotificationsUrbanAirship.MyAutoPilot;
import android.util.Log;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;

public class RegisterWithUAFunction implements FREFunction {

    private static final String TAG = "RegisterWithUAFunction";

    @Override
    public FREObject call(FREContext context, FREObject[] args) {
        // TODO Auto-generated method stub

        try{
            MyAutoPilot autoPilot = new MyAutoPilot();
            autoPilot.setAppKey(args[0].getAsString());
            autoPilot.setAppSecret(args[1].getAsString());
            autoPilot.setGcmSender(args[2].getAsString());
            autoPilot.setInProduction(args[3].getAsBool());

            Log.i(TAG, "About to execute takeOff");

            autoPilot.execute(context.getActivity().getApplication());
        }
        catch(FREInvalidObjectException e){
            Log.e(TAG, e.getMessage());
        }
        catch(FRETypeMismatchException e){
            Log.e(TAG, e.getMessage());
        }
        catch(FREWrongThreadException e){
            Log.e(TAG, e.getMessage());
        }
        catch(Exception e){
            Log.e(TAG, e.getMessage());
        }

        return null;
    }

}

IntentReceiver与http://docs.urbanairship.com/reference/libraries/android/latest/reference/com/urbanairship/Autopilot.html

完全相同

非常感谢任何帮助

0 个答案:

没有答案