2014-10-08 65 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

相关问题