【问题标题】:Android Cognito push syncAndroid Cognito 推送同步
【发布时间】:2016-03-20 19:47:41
【问题描述】:

我正在尝试将 cognito 与 android 应用程序集成以同步数据。 我正在关注 AWS 在 this 链接上提供的文档

根据这个文档,应该有一个 BroadcastReceiver 来接收推送同步。

但我已经在我的应用程序中使用了推送通知。根据google documentation,没有提到任何广播接收器。 所有通知都在 GcmListenerService 的 public void onMessageReceived(String from, Bundle data); 方法中接收。

谁能帮我弄清楚aws push sync正在谈论的广播接收器?

【问题讨论】:

  • 监听器和接收器发送通知的目的相同,但有一些基本区别,您可以在此处查看 [stackoverflow.com/questions/14794684/…
  • 感谢@Rachit Dhall 的回复。两者的目的相同,但是在 onReceive 中有一个“意图”作为参数,我可以使用该意图来获取诸如“PushSyncUpdate update = client.getPushSyncUpdate(intent);”之类的信息。但是如何在 GcmListenerService 的“onMessageReceived(String from, Bundle data)”方法中实现。你有我的问题吗?
  • 我希望下面的答案解决了这个问题。我将努力更新文档。

标签: android amazon-web-services amazon-cognito


【解决方案1】:

BroadcastReceiver 已被弃用,AWS 尚未更新其文档。但是您可以简单地从GcmListenerService 中提供的数据Bundle 创建一个Intent:

@Override
public void onMessageReceived(String from, Bundle data) {
    CognitoSyncManager manager;
    try {
      manager = CognitoSyncClientManager.getInstance();
    } catch (IllegalStateException ise) {
      Log.w(TAG, "sync manager is not initialized");
      return;
    }

    Intent intent = new Intent();
    intent.putExtras(data);
    PushSyncUpdate update = manager.getPushSyncUpdate(intent);
    //...

【讨论】:

    猜你喜欢
    • 2017-01-26
    • 2018-03-19
    • 2015-03-04
    • 1970-01-01
    • 2017-07-02
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多