2014-10-08 64 views
1

我正在開發一個可與推送通知一起使用的Worklight應用程序。我目前正在Android上進行測試,並且已經有適配器嚮應用發送推送通知。問題是:應用程序只在前臺接收它。如果它位於背景上,它不會收到它,並且在通知區域中顯示一條消息後將其打開。當我點擊通知區域內的消息時,該應用程序也不會打開。點擊通知區域中的郵件時,應用程序未打開

我學習了PushNotifications示例,它看起來像我做的一樣。我在Android清單文件中對照例子中的權限等進行了交叉檢查。但是,它似乎並不奏效。下面是運行PushNotifications示例時日誌的摘錄。

10-08 09:58:48.227: V/GCMBroadcastReceiver(2771): onReceive: com.google.android.c2dm.intent.RECEIVE 
10-08 09:58:48.227: V/GCMBroadcastReceiver(2771): GCM IntentService class: com.PushNotifications.GCMIntentService 
10-08 09:58:48.227: V/GCMBaseIntentService(2771): Acquiring wakelock 
10-08 09:58:48.237: V/GCMBaseIntentService(2771): Intent service name: GCMIntentService-DynamicSenderIds-4 
10-08 09:58:48.237: D/GCMIntentService(2771): GCMIntentService.onMessage in GCMIntentService.java:101 :: WLGCMIntentService: Received a message from the GCM server 
10-08 09:58:48.237: W/GCMIntentService(2771): GCMIntentService.onMessage in GCMIntentService.java:108 :: Unable to update badge while received push notification, becasue failed to parse badge number null, badge must be an integer number. 
10-08 09:58:48.257: V/GCMBaseIntentService(2771): Releasing wakelock 
10-08 09:58:48.257: D/GCMIntentService(2771): GCMIntentService.addToIntentQueue in GCMIntentService.java:123 :: WLGCMIntentService: App is not on foreground. Queue the intent for later re-sending when app is back on foreground. 
10-08 09:58:48.277: D/push(2771): Push$1.onReceive in Push.java:91 :: Push: Queuing message for dispatch to javascript 
10-08 09:58:48.277: D/GCMIntentService(2771): GCMIntentService.onUnhandled in GCMIntentService.java:164 :: WLGCMIntentService: Showing notification for unhandled Message(alert=Hoi-hoi, badge=1, sound=null, payload={"alias":"myPush","custom":"data"}) 
10-08 09:59:20.837: D/Whitelist(2771): Unlimited access to network resources 
10-08 09:59:20.837: I/CordovaLog(2771): Changing log level to DEBUG(3) 
10-08 09:59:20.837: D/CordovaActivity(2771): Resuming the App 
10-08 09:59:20.837: D/CordovaActivity(2771): CB-3064: The errorUrl is null 
10-08 09:59:20.877: W/EGL_emulation(2771): eglSurfaceAttrib not implemented 
10-08 09:59:20.907: D/dalvikvm(2771): GC_FOR_ALLOC freed 810K, 27% free 4785K/6516K, paused 25ms, total 25ms 
10-08 09:59:20.917: D/push(2771): Push.dispatchPending in Push.java:390 :: Dispatching to javascript Message(alert=Hoi-hoi, badge=1, sound=null, payload={"alias":"myPush","custom":"data"}) 
10-08 09:59:20.917: D/WLClient(2771): WLClient$ActivityListener.onActivityStarted in WLClient.java:1180 :: on activity started com.PushNotifications.PushNotifications 
10-08 09:59:20.917: D/WLClient(2771): WLClient$ActivityListener.onActivityResumed in WLClient.java:1169 :: on activity resumed com.PushNotifications.PushNotifications . activity count = 1 

我的一個幾乎是相同的,除了從下面的第三行(D /推(2771):Push.dispatchPending)丟失。它似乎從未將排隊的事件分發給應用程序。

我可能會錯過什麼?

Worklight版本是6.2.0.00-20140922-2259。

+0

在Studio中創建應用程序後,您是否已將res \ values \ strings.xml中的應用程序重命名? – 2014-10-08 14:32:01

+0

此外,始終提及您的Worklight Studio版本和內部版本號。 – 2014-10-08 14:32:18

+0

我已更新版本號的問題。 你的意思是在strings.xml中的app_name?我沒有改變它。它從應用程序描述符中顯示的名稱中複製(我想)。但是,它與應用程序ID不同。如果您的意思是wlAppIdTitle,則默認值爲「App ID」(就像推送示例應用程序一樣)。 – 2014-10-08 15:07:03

回答

1

更新:這實際上按預期工作。以下是技術說明:

res \ values \ strings.xml中的app_name值在內部用於創建Intent對象。因此,當應用程序關閉並且GCMIntentService收到消息時,它會創建一個動作爲<packagename>.<app_name>的意圖,並將其發送到通知服務以在通知欄中顯示通知。

這是意圖名在AndroidManifest.xml中用來表示該應用必須建立在竊聽通知發佈:

<activity android:name=".PushNotifications" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="sensor"> 
    .... 
    <intent-filter> 
     <action android:name="com.PushNotifications.PushNotifications.NOTIFICATION"/> 
     <category android:name="android.intent.category.DEFAULT"/> 
    </intent-filter> 

所以,現在如果app_name更改爲其他任何字符串,在內部的意圖將被創建爲com.PushNotifications.<new_name>
但AndroidManifest.xml仍然有例如com.PushNotifications.PushNotifications(在示例應用程序的情況下),所以應用程序不會啓動,因爲意圖操作不同。

要顯示與不同的名稱申請,請按照下列步驟操作:

  1. 在strings.xml中,添加一個額外的new_name_value
  2. 在AndroidManifest.xml中,修改標籤與新的字符串名稱

    <application android:label="@string/app_new_name" android:icon="@drawable/icon"> 
    <activity android:name=".PushNotifications" android:label="@string/app_new_name"... 
    

從評論:似乎如果在Android的res \ values \ strings.xml中更改應用程序名稱,應用程序在點擊傳入通知後將不會啓動。

開發團隊目前正在調查一個類似的報告,因此我的建議是打開一個PMR,以便爲您的Worklight版本進行調查。

目前唯一的解決方法是改回應用程序的名稱爲最初創建的名稱爲應用程序,

或者,創建一個新的應用程序,但與所需的名稱此時而不是應用程序後更改它的創建。

+0

謝謝,Idan,我確認它有效。然而,從strings.xml中使用UI字符串(意味着包含面向用戶的翻譯字符串,允許使用空格和任何允許的字符)作爲意圖的標識符,看起來不是一個很好的設計選擇。 – 2014-10-09 07:48:03

+0

我會確保通過這個來看看是否有更好的路徑 – 2014-10-09 08:04:14

+0

Idan,請注意:在不久的將來(下半年)是否有計劃支持推送消息BB10? – 2014-10-09 11:37:54

相關問題