单击通知区域中的消息时未打开应用程序

时间:2014-10-08 14:30:15

标签: android push-notification ibm-mobilefirst

我正在开发一个适用于推送通知的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 / push(2771):Push.dispatchPending)丢失之外,我的差不多了。它似乎永远不会将排队的事件发送到应用程序。

我可能缺少什么?

Worklight版本为6.2.0.00-20140922-2259。

1 个答案:

答案 0 :(得分:2)

更新:这实际上是按预期工作的。以下是技术说明:

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"...
    

  3. 从评论中看来:如果在Android的res \ values \ strings.xml中更改应用程序名称,则在点击传入通知后应用程序将无法启动。

    开发团队目前正在调查类似的报告,因此我的建议是打开PMR,以便对您的Worklight版本进行调查。

    目前唯一可用的解决方法是将应用程序名称更改回应用程序的最初创建名称,

    或者,创建一个新的应用程序,但这次使用所需的名称,而不是在创建应用程序后更改它。