0

我正在关注这个GCM 示例,它工作正常,只需告诉我服务器如何向每个注册设备发送消息的机制,它将如何唯一标识每个设备。我SENDER_IDregId什么服务器如何唯一标识我的设备 php 服务器如何在没有 SMS 电子邮件服务的情况下向每个设备发送消息 请告诉我它的机制 请告诉我它将如何在这个应用程序中工作 我几乎没有这个

String SENDER_ID = "748495904142"

我从https://code.google.com/apis/console/?pli=1#project:748495904142:access收到

final String regId = GCMRegistrar.getRegistrationId(this);

// Check if regid already presents
if (regId.equals("")) {
    // Registration is not present, register now with GCM           
    GCMRegistrar.register(this, SENDER_ID);
} else {
    // Device is already registered on GCM
    if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.              
        Toast.makeText(getApplicationContext(),"Already registered with GCM",
        Toast.LENGTH_LONG).show();
    } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask = new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                // Register on our server
                // On server creates a new user
                ServerUtilities.register(context, name, email, regId);
                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                mRegisterTask = null;
            }
        };
    }
}
4

2 回答 2

1

SENDER_ID 是服务器用来区分与服务器关联的不同项目的项目 ID。

REG_ID 是服务器用来区分向服务器注册的不同移动设备的唯一标识。

现在例如,相同的移动设备与两个不同的项目相关联并且与相同的服务器相关联,因此为服务器提供了区分这两个项目并将各自的消息发送到移动设备的便利。

于 2013-09-24T09:18:07.670 回答
0

当您在 API 控制台上注册项目时,您会获得项目的编号,该编号是 SENDER_ID,您也可以从控制台获得 API 密钥。在android中执行时

final String regId = GCMRegistrar.getRegistrationId(this);

然后手机检查gcm的注册,如果已经注册了gcm服务器,那么它将返回一个regId。这些 id 对于不同的手机是不同的。gcm 服务器使用此注册 ID 识别您的手机。获得 regid 后,我们将其保存到我们的数据库中以备将来使用。在服务器端,我们只是将消息和注册 id 发送到 gcm 服务器,gcm 服务器使用注册 id 识别手机并将通知发送到相应的手机。

于 2014-02-01T11:45:11.767 回答