UrbanAirship android广播接收器

时间:2012-06-12 20:28:43

标签: android push-notification android-c2dm urbanairship.com

com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime  java.lang.RuntimeException: Unable to start service com.urbanairship.push.PushService@40cfdc08 with Intent { act=com.urbanairship.push.START cmp=com.myapp.myapp/com.urbanairship.push.PushService }: java.lang.IllegalStateException: UAirship.takeOff() must be called every time Application.onCreate() is invoked.
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2499)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at android.app.ActivityThread.access$1900(ActivityThread.java:132)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1220)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at android.os.Handler.dispatchMessage(Handler.java:99)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at android.os.Looper.loop(Looper.java:137)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at android.app.ActivityThread.main(ActivityThread.java:4575)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at java.lang.reflect.Method.invokeNative(Native Method)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at java.lang.reflect.Method.invoke(Method.java:511)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at dalvik.system.NativeStart.main(Native Method)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime  Caused by: java.lang.IllegalStateException: UAirship.takeOff() must be called every time Application.onCreate() is invoked.
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at com.urbanairship.push.PushService.onStart(Unknown Source)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at android.app.Service.onStartCommand(Service.java:438)
23:03:56.422    21926   com.myapp.myapp:com.urbanairship.process    ERROR   AndroidRuntime      at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2482)

我正在尝试将UrbanAirship集成到我的应用程序中,在调用takeOff之后抛出上述异常,如果我修改了该行:

<service android:name="com.urbanairship.push.PushService" android:process=":com.urbanairship.process"/>

..没有android:进程部分它可以工作但是当推送消息到达时我的PushBroadcastReceiver没有被调用(断点没有被击中)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          android:versionName="3.61 beta 1"
          android:versionCode="71"
          android:installLocation="auto" package="com.myapp.myapp">

    <uses-sdk android:minSdkVersion="3"
            android:targetSdkVersion="4"/>


    <uses-feature android:name="android.hardware.camera"/>
    <application 
        android:label="@string/app_name">
        <activity android:name=".client.android.SplashScreen"
              android:screenOrientation="portrait"
              android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".client.android.CaptureActivity"
              android:screenOrientation="landscape"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
              android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="com.myapp.myapp.client.android.CaptureActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".client.android.PreferencesActivity"
              android:label="@string/preferences_name"
              android:screenOrientation="portrait">

        </activity>

        <activity android:name=".client.android.PushBroadcastReceiver">

        </activity>

        <activity android:name=".client.android.AboutActivity"
              android:label="@string/menu_about">
            <intent-filter>
                <action android:name="com.myapp.myapp.client.android.AboutActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

        </activity>

        <receiver android:name="com.urbanairship.CoreReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.ACTION_SHUTDOWN" />
            </intent-filter>
        </receiver>

        <receiver android:name="com.urbanairship.push.c2dm.C2DMPushReceiver"
              android:permission="com.google.android.c2dm.permission.SEND">

            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.myapp.myapp" />
            </intent-filter>

            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.myapp.myapp" />
            </intent-filter>

        </receiver>

        <service android:name="com.urbanairship.push.PushService" android:process=":com.urbanairship.process"/>
        <receiver android:name="com.myapp.myapp.client.android.PushBroadcastReceiver" />

    </application>


    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.FLASHLIGHT"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />


    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <permission android:name="com.myapp.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.myapp.myapp.permission.C2D_MESSAGE" />

    <!-- This app has permission to register and receive message -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

</manifest>

1 个答案:

答案 0 :(得分:0)

你在哪里打电话给takeOff?看起来您没有使用AutoPilot或提供在onCreate方法中调用起飞的自定义应用程序。

首先创建一个调用takeOff的CustomApplication类:

public class CustomApplication extends Application {

    @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
            }
        });
    }
}

然后在清单中设置应用程序: <application name="CustomApplication"

我还会从您的清单中删除进程的使用。他们几乎不再是一个好主意了。它们会使应用程序逻辑复杂化并浪费更多资源。

有关Urban Airship的更多信息 - http://docs.urbanairship.com/platform/android.html