点击通知栏消息后应用程序未打开

3
我正在开发一个与推送通知相关的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。


在 Android Studio 中创建应用后,你是否已经在 res\values\strings.xml 文件中重命名了它? - Idan Adar
同时,请始终提及您的 Worklight Studio 版本和构建号。 - Idan Adar
我已经更新了问题,并附上了版本号。 你指的是strings.xml中的app_name吗?我没有改过它。我想它是从应用描述符中的显示名称复制而来的。但是,它与应用程序ID不同。如果你指的是wlAppIdTitle,它的默认值是“App ID”(就像推送示例应用程序一样)。 - Andrey Ch
经过一些实验,我得出结论,这确实与 res/values/strings.xml 中的 app_name 和 push_notification_title 有关。我将它们设置为我的项目的原始名称(第一次迭代中的10+),突然之间它正常工作了。但是,这意味着我被困在一个旧的应用程序内部名称上。有没有办法更改它? - Andrey Ch
开发团队已经在调查类似的报告,所以我的建议是打开一个PMR,以便在修复程序可用时获得修复。 - Idan Adar
请查看我的更新答案。 - Idan Adar
1个回答

3

更新:实际上这正常工作。以下是技术解释:

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

这是在 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更改为任何其他字符串,内部Intent将创建为com.PushNotifications.<new_name>


但是,AndroidManifest.xml仍然具有例如com.PushNotifications.PushNotifications(在示例应用程序的情况下),因此该应用程序未被作为意图操作启动。

要使用不同的名称显示应用程序,请按照以下步骤进行:

  1. In strings.xml, add an additional new_name_value
  2. In AndroidManifest.xml , modify the label with the new string name

    <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文件中更改应用程序名称,则在点击传入通知后应用程序将无法启动。

开发团队目前正在调查一个类似的报告,因此我的建议是要针对您使用的Worklight版本打开一个PMR来进行调查。

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

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


谢谢,Idan。我确认它起作用了。不过,将 strings.xml 中的 UI 字符串(用于包含用户界面翻译字符串,允许使用空格和任何字符)用作意图标识符似乎不是一个很好的设计选择。 - Andrey Ch
我会确保将这个传递下去,以查看是否有更好的路径。 - Idan Adar
Idan,顺便问一下:在不久的将来(下半年),是否有支持BB10推送消息的计划? - Andrey Ch
2
这超出了我的薪资等级所知道的范围。 - Idan Adar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接