Urban Airship推送通知并未推送数据

时间:2012-03-19 09:39:54

标签: android urbanairship.com

我是都市飞艇的新手,并将其整合到我的Android应用程序中。从Airship获得样品来源,我按照相同的程序调用飞艇进入我的应用程序。但每当我发送推送通知,我都无法通过我的设备。我在我的资料中给出的包装名称与我在Airship中给出的相同。任何人都可以指导我如何在Android应用程序中集成Urban Airship。

   AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);

    // Optionally, customize your config at runtime:
    //
    // options.inProduction = false;
     options.developmentAppKey = "My Key";
     options.developmentAppSecret "My key";

    UAirship.takeOff(this, options);
    Logger.logLevel = Log.VERBOSE;

    //use CustomPushNotificationBuilder to specify a custom layout
    CustomPushNotificationBuilder nb = new CustomPushNotificationBuilder();

    nb.statusBarIconDrawableId = R.drawable.icon_small;//custom status bar icon

    nb.layout = R.layout.notification;
    nb.layoutIconDrawableId = R.drawable.icon;//custom layout icon
    nb.layoutIconId = R.id.icon;
    nb.layoutSubjectId = R.id.subject;
    nb.layoutMessageId = R.id.message;

    // customize the sound played when a push is received
    //nb.soundUri = Uri.parse("android.resource://"+this.getPackageName()+"/" +R.raw.cat);

    PushManager.shared().setNotificationBuilder(nb);
    PushManager.shared().setIntentReceiver(IntentReceiver.class);

}

当我编译上面的代码时,我正在

e   03-19 16:13:35.455: ERROR/AndroidRuntime(1247): Uncaught handler: thread main exiting due to uncaught exception
03-19 16:13:35.545: ERROR/AndroidRuntime(1247): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.XYZ}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at android.os.Looper.loop(Looper.java:123)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at android.app.ActivityThread.main(ActivityThread.java:3948)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at java.lang.reflect.Method.invokeNative(Native Method)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at java.lang.reflect.Method.invoke(Method.java:521)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at dalvik.system.NativeStart.main(Native Method)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:281)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at com.XYZ.onCreate(ManualUpdate.java:86)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
03-19 16:13:35.545: ERROR/AndroidRuntime(1247):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)

2 个答案:

答案 0 :(得分:1)

尝试添加" airshipconfig.properties"文件到资产:

developmentAppKey = key
developmentAppSecret = key
productionAppKey = key
productionAppSecret = key
inProduction = true
transport = c2dm
c2dmSender = email

并删除:

options.developmentAppKey = "My Key";
options.developmentAppSecret "My key";

来自你的代码。

AndroidManifest.xml怎么样?你做对了吗?

       <!-- REQUIRED -->
    <receiver android:name="com.urbanairship.CoreReceiver">
        <!-- REQUIRED IntentFilter - For Helium and Hybrid -->
        <intent-filter>
          <action android:name="android.intent.action.BOOT_COMPLETED" />
          <action android:name="android.intent.action.ACTION_SHUTDOWN" />
        </intent-filter>
    </receiver>

    <!-- REQUIRED for C2DM and Hybrid -->
    <receiver android:name="com.urbanairship.push.c2dm.C2DMPushReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
      <!-- Receive the actual message -->
      <intent-filter>
          <action android:name="com.google.android.c2dm.intent.RECEIVE" />
          <category android:name="com.XXXXXXXX" />
      </intent-filter>
      <!-- Receive the registration id -->
      <intent-filter>
          <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
          <category android:name="com.XXXXXXXX" />
      </intent-filter>
    </receiver>

    <!-- REQUIRED -->
    <!-- The 'android:process' parameter is optional. Set it to a value starting
        with a colon (:) to make it run in a separate,
        private process -->
    <service android:name="com.urbanairship.push.PushService"
            android:process=":com.urbanairship.push.process"/>

    <!-- OPTIONAL, if you want to receive push, push opened and registration completed intents -->
    <receiver android:name="com.XXXXXXXXXX.service.IntentReceiver" />

请记住,您应该始终从UrbanAirShip中看到一些日志信息。特别注册信息。检查您的设备是否已添加到城市网站上的设备中。

答案 1 :(得分:0)

对于android&amp;的PhoneGap ::

在src目录文件中创建一个包含以下内容的xx.java

package com.myapp.mobile.push.handler;
import com.phonegap.DroidGap;
import android.webkit.WebView;
import com.urbanairship.Logger;
import com.urbanairship.push.PushManager;
import com.urbanairship.push.PushPreferences;

public class extraFunctions  extends DroidGap {
    public WebView mAppView;
    private DroidGap mGap;
    public extraFunctions(DroidGap gap, WebView view)
     {
        mAppView = view;
        mGap = gap;
     }   

     public String getAUID(){
         PushPreferences prefs = PushManager.shared().getPreferences();
         return prefs.getPushId();
     }

}

要访问它:  在您的资产/ www

使用javascript调用:window.extraFunctions.getAUID();