0

I m using Google cloud message to send push message to device, but it have a large delay to send (if i manually click in sync google account, the message come on time). I want when i open my app (onResume activity) do "force sync" of google account.

i m trying this way:

Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_FORCE, true);
Account[] accounts = AccountManager.get(context).getAccounts();
for (Account account : accounts) {
    SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
    for (SyncAdapterType type : types) {
        if (account.type.equals(type.accountType)) {
            boolean isSyncable = ContentResolver.getIsSyncable(account, type.authority) > 0;
            if (isSyncable) {
                ContentResolver.requestSync(account, type.authority, extras);
            }
        }
    }
}

but it ill try sync all account in all ways, AND it dont work my message don't come like when i click in the menu button of sync.

how i can force (in the better way) my app to check if it have some message in google .cloud?

4

1 回答 1

0

这不是您应该使用 Google Cloud Messaging(或任何移动推送通知服务)的方式。使用 GCM 的目的是在应用程序未运行时接收消息,以提醒用户他/她可能会感兴趣的事件,并(希望)让他们启动您的应用程序。

当您的应用程序已经启动时,尝试找出是否有任何待处理的 GCM 消息由您的服务器发送但尚未交付是没有意义的。相反,您可以简单地调用您的服务器并获取您需要显示给应用程序用户的所有数据(包括 GCM 消息中尚未到达的任何数据)。

于 2013-09-18T13:26:45.340 回答