2012-03-19 118 views
0

我是城市飛艇的新手,並將其集成到我的Android應用程序中。從飛艇獲得了樣品來源,我遵循相同的程序,以便將飛艇引入我的應用程序。但每當我發送推送通知,我不能通過我的設備。包的名字,我給我的來源同樣我給了飛艇。任何人都可以引導我如何在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) 
+0

你能顯示一些代碼嗎?你能看到任何註冊日誌信息嗎?我在我的最新應用中使用它,它工作正常。 – goodm 2012-03-19 09:42:35

+0

我dint看到任何註冊日誌信息..你可以請給我一個指導..我試圖超過2天。我無法得到適當的解決方案。 – RAAAAM 2012-03-19 09:46:42

回答

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的日誌信息。特別註冊信息。請檢查您的設備是否已添加到城市網站上的設備。使用你的資產/ WWW

+1

是的,查看通知。但你不需要它來註冊你的設備。請記住,城市並不總是工作。幾次我收到通知的問題,但它始終註冊我的設備。 – goodm 2012-03-19 10:02:27

+0

在UAirship.takeoff中獲取錯誤,以至於我將代碼更改爲'UAirship.takeOff((Application)this.getApplicationContext(),options);'這是這個儀式..? – RAAAAM 2012-03-19 10:02:54

+0

我應該給清單中,在這一行「category android:name =」com.XXXXXXXX「我可以給我自己的活動.. ?? – RAAAAM 2012-03-19 10:05:51

0

爲Android &的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(); 
    } 

} 

要訪問javascript call:window.extraFunctions.getAUID();

相關問題