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

标签 android push-notification ibm-mobilefirst

我正在开发一个适用于推送通知的 Worklight 应用程序。我目前正在 Android 上进行测试,并让适配器向应用程序发送推送通知。问题是:应用程序只有在前台时才会收到它。如果它在后台,它不会收到它,我在通知区域显示一条消息后打开它。当我点击通知区域内的消息时,应用程序也没有打开。

我研究了 PushNotifications 示例,看起来我在做同样的事情。我根据示例中的内容交叉检查了 Android list 文件中的权限等。但是,它似乎不起作用。以下是运行 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) 不见了。它似乎从不将排队的事件分派(dispatch)给应用程序。

我可能遗漏了什么?

Worklight 版本为 6.2.0.00-20140922-2259。

最佳答案

更新:这实际上按预期工作。这是技术解释:

app_name res\values\strings.xml 中的值在内部用于创建 Intent 对象。因此,当应用程序关闭并且 GCMIntentService 收到一条消息时,它会创建一个操作为 <packagename>.<app_name> 的 Intent 。并将其发送到通知服务以在通知栏中显示通知。

这是 AndroidManifest.xml 中使用的 Intent 名称,用于指示必须在点击通知时启动应用:

<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更改为任何其他字符串,Intent 将在内部创建为 com.PushNotifications.<new_name> .
但是 AndroidManifest.xml 仍然有例如 com.PushNotifications.PushNotifications (在示例应用程序的情况下),因此应用程序未启动,因为 Intent 操作不同。

要以不同的名称显示应用程序,请按照下列步骤操作:

  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 版本也对其进行调查。

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

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

关于android - 单击通知区域中的消息时未打开应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26259482/

相关文章:

ibm-mobilefirst - IBM Worklight - AppCenter 应用程序缺少插件 'com.ibm.mobile.InstallerPlugin'

android - 使用游标查询我的数据库

ios - 使用分发证书发出测试推送通知

android - 由于找不到 View ID,项目外部的文件导致构建失败

android - 当我将我的模块与那个应用程序集成时,两个应用程序收到相同的通知消息

push-notification - 推送通知 : Why use Amazon SNS over Google's GCM/FCM?

blackberry - IBM Worklight - "config.xml is malformed xml or could not be found in the application' s 根”

java - Android ViewFlipper中Rotate3dAnimation的更好实现

java - 如何在 Android 连接丢失后停止进度条旋转