IBM Worklight - Android 上的推送通知

Posted

技术标签:

【中文标题】IBM Worklight - Android 上的推送通知【英文标题】:IBM Worklight - Push notification on Android 【发布时间】:2013-08-06 05:53:49 【问题描述】:

我正在尝试 android 手机和平板电脑的推送通知,我们正在使用 IBM Worklight (see blog post) 提供的示例代码。

我们已经在 Google GCM 上注册并获得了项目 id 和 API 密钥;该代码在平板电脑上运行良好,但是当我使用手机运行相同时 isSubscribed 返回 false,任何人都可以测试这里给出的代码,让我们知道我们做错了什么,因为它不能在多个设备上工作。

来自第一台设备的 LogCat - 运行 Android v3.2 的平板电脑 工作正常。

08-06 17:48:35.110: V/webview(11093):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
08-06 17:48:40.930: V/webview(11093):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
08-06 17:48:40.950: D/PushApplication(11093): Request [http://172.20.10.8:8080/apps/services/api/PushApplication/android/notifications]
08-06 17:48:41.470: D/PushApplication(11093): response [http://172.20.10.8:8080/apps/services/api/PushApplication/android/notifications] success: /*-secure-
08-06 17:48:41.470: D/PushApplication(11093): "errors":[],"isSuccessful":true,"warnings":[],"info":[]*/
08-06 17:48:41.470: V/(11093): ResourceHandle
08-06 17:48:41.520: D/dalvikvm(11093): GC_CONCURRENT freed 331K, 6% free 7957K/8455K, paused 3ms+4ms
08-06 17:48:44.710: V/(11093): ResourceHandle
08-06 17:49:02.820: V/GCMBroadcastReceiver(11093): onReceive: com.google.android.c2dm.intent.RECEIVE
08-06 17:49:02.820: V/GCMBroadcastReceiver(11093): GCM IntentService class: com.PushApplication.GCMIntentService
08-06 17:49:02.820: V/GCMBaseIntentService(11093): Acquiring wakelock
08-06 17:49:02.830: V/GCMBaseIntentService(11093): Intent service name: GCMIntentService-804999789155-4
08-06 17:49:02.830: D/WLDroidGap(11093): Received a message from the GCM server
08-06 17:49:02.830: V/GCMBaseIntentService(11093): Releasing wakelock
08-06 17:49:02.840: D/WLDroidGap(11093): Queuing message for dispatch to javascript
08-06 17:49:02.840: D/WLDroidGap(11093): Dispatching to javascript Message(alert=got a new message, badge=1, sound=sound.mp3, payload=
08-06 17:49:02.840: D/WLDroidGap(11093):    "alias": "myPush",
08-06 17:49:02.840: D/WLDroidGap(11093):    "foo": "bar"
08-06 17:49:02.840: D/WLDroidGap(11093): )
08-06 17:49:02.840: D/PushApplication(11093): WL.Client.Push received notification for alias myPush

来自第二台设备的 LogCat - 运行 Android v4.0.4 的平板电脑 订阅按钮已禁用

01-01 10:02:31.740: V/webview(8635):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
01-01 10:02:31.840: V/GCMBroadcastReceiver(8635): onReceive: com.google.android.gcm.intent.RETRY
01-01 10:02:31.840: V/GCMBroadcastReceiver(8635): GCM IntentService class: com.PushApplication.GCMIntentService
01-01 10:02:31.840: V/GCMBaseIntentService(8635): Acquiring wakelock
01-01 10:02:31.850: V/GCMBaseIntentService(8635): Intent service name: GCMIntentService-804999789155-2
01-01 10:02:31.850: E/GCMBaseIntentService(8635): Received invalid token: 1101110000000111011000111110100011101100101100011101100111100011

我们已经从示例代码中删除了禁用,这允许我们检查平板电脑 2 是否被订阅,下面的日志清楚地显示设备没有被订阅。

01-01 10:27:13.440: V/webview(9400): NO_FAST_DRAW = false
01-01 10:27:13.640: V/webview(9400):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
01-01 10:27:13.660: E/PushApplication(9400): Can't subscribe, notification token is not updated on the server
01-01 10:27:20.840: V/GCMBroadcastReceiver(9400): onReceive: com.google.android.gcm.intent.RETRY
01-01 10:27:20.840: V/GCMBroadcastReceiver(9400): GCM IntentService class: com.PushApplication.GCMIntentService
01-01 10:27:20.840: V/GCMBaseIntentService(9400): Acquiring wakelock
01-01 10:27:20.860: V/GCMBaseIntentService(9400): Intent service name: GCMIntentService-804999789155-6
01-01 10:27:20.860: V/GCMRegistrar(9400): Registering app com.PushApplication of senders 804999789155
01-01 10:27:20.870: V/GCMBaseIntentService(9400): Releasing wakelock
01-01 10:27:23.340: V/GCMBroadcastReceiver(9400): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-01 10:27:23.340: V/GCMBroadcastReceiver(9400): GCM IntentService class: com.PushApplication.GCMIntentService
01-01 10:27:23.340: V/GCMBaseIntentService(9400): Acquiring wakelock
01-01 10:27:23.340: V/GCMBaseIntentService(9400): Intent service name: GCMIntentService-804999789155-7
01-01 10:27:23.340: D/GCMBaseIntentService(9400): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-01 10:27:23.340: D/GCMBaseIntentService(9400): Registration error: SERVICE_NOT_AVAILABLE

【问题讨论】:

手机的安卓版本是多少? LogCat 显示什么?您的 Worklight 版本是多少? 平板电脑是三星 Galaxy 平板电脑,运行 android os 3.2,手机是三星 s2,操作系统版本是 4.0.4,但不工作 所以你说你登录到应用程序,订阅然后点击isSubscribe,但它返回false?您为实现这一目标而采取的实际流程是什么? LogCat 显示什么? 嗨 Idan,我已经分享了日志猫,还有一个问题是我的第二个平板电脑由于某种原因没有被订阅,这就是问题所在,但我无法找到解决方法。请帮忙 您是尝试在两台平板电脑上使用相同的用户名登录,还是使用不同的用户名登录? 【参考方案1】:

请检查您的互联网连接,因为您在第二台设备的日志中看到的错误是:

01-01 10:27:23.340: V/GCMBaseIntentService(9400): Intent service name: GCMIntentService-804999789155-7
01-01 10:27:23.340: D/GCMBaseIntentService(9400): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-01 10:27:23.340: D/GCMBaseIntentService(9400): Registration error: SERVICE_NOT_AVAILABLE

这意味着您的应用无法向 GCM 服务注册以获取令牌,因为 GCM 服务似乎不可用,因此错误 SERVICE_NOT_AVAILABLE,可能是因为您的互联网连接问题或 GCM 可能在您尝试时不可用这。所以多尝试几次。

另外请注意,现在您正在另一台设备上运行您的应用程序,这意味着即使您以同一用户(如在第一台设备上)登录,您也需要再次进行订阅。所以 isSubscribed() 返回 false 是正确的.

订阅调用本质上是指将这个特定设备上的登录用户订阅到给定的事件源。由于您尚未订阅第二台设备(即使同一用户在第一台设备上订阅),isSubscribed() 返回 false。

【讨论】:

以上是关于IBM Worklight - Android 上的推送通知的主要内容,如果未能解决你的问题,请参考以下文章

IBM Worklight - Android 上的推送通知

IBM Worklight 和推送通知问题

无法在真实设备 android 中运行 IBM worklight 应用程序

IBM Worklight - 如何使 Android 环境代码“独立于”生成的项目?

IBM Worklight SimpleDialog 平台限制

IBM Tealeaf 和 Worklight 6.1.0.01-2 Android 应用程序