gpt4 book ai didi

android - Knox 内部的 Google 云消息传递。如何接收消息?

转载 作者:行者123 更新时间:2023-11-30 01:37:27 25 4
gpt4 key购买 nike

我的应用程序在接收来自 Knox 内部 GCM 的消息时遇到了很大的问题。 Knox 之外的同一个应用程序可以毫无问题地接收消息。同一个应用程序在外部和内部注册到 GCM。为什么 GCM 在 Knox 内部不起作用?必须做什么才能在 Knox 中接收 GCM 消息?

Device: Samsung S5
Samsung Knox version: 2.3
Google Play Services: 8.4.89

最佳答案

好的,我自己找到了解决方案。问题出在 GCM 服务的注册上。

我使用 GCM 指南 ( https://developers.google.com/cloud-messaging/android/start ) 中的注册代码:

public class RegistrationIntentService extends IntentService {
@Override
public void onHandleIntent(Intent intent) {
// ...

InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

// ...
}
}

实际上它运行良好。在 Android 和 Knox 中, token 已按预期接收。但是在 Knox 上没有来自 GCM 的任何消息。在查看各种应用程序后,我使用了不同的注册代码:

public class RegistrationIntentService extends IntentService {
@Override
public void onHandleIntent(Intent intent) {
// ...

GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String token = gcm.register(getString(R.string.gcm_defaultSenderId));

// ...
}
}

...神奇的是,就是这样。希望它对某人有用。


关于android - Knox 内部的 Google 云消息传递。如何接收消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34946652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com