0
votes

I'm trying to implement google's GCM on my android application and I came across a question about the .register() function.

private void registerInBackground() {
    new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
            String msg = "";
            try {
                if (gcm == null) {
                    gcm = GoogleCloudMessaging.getInstance(context);
                }
                regid = gcm.register(SENDER_ID);
                Log.d(TAG, "registered gcm");
                msg = "Device registered, registration ID=" + regid;
                Log.d(TAG, "Current Device's Registration ID is: "+msg);  

                // You should send the registration ID to your server over HTTP, so it
                // can use GCM/HTTP or CCS to send messages to your app.
              //  sendRegistrationIdToBackend();

                // For this demo: we don't need to send it because the device will send
                // upstream messages to a server that echo back the message using the
                // 'from' address in the message.

                // Persist the regID - no need to register again.
                storeRegistrationId(context, regid);
            } catch (IOException ex) {
                msg = "Error :" + ex.getMessage();
                // If there is an error, don't just keep trying to register.
                // Require the user to click a button again, or perform
                // exponential back-off.
            }
            return msg;
        }

For regid = gcm.register(SENDER_ID);, what type of connection would the application use to send over to GCM in order to register the SENDER_ID? Does it only do it via wi-fi or do I need to establish a server in order to register with the GCM. My main question is, how does the client app register with GCM to obtain that registration ID?

1

1 Answers

1
votes

AFAIR, no it does not need a custom server from your side to receive the Registration ID. Google servers sends that to the user device. You( your custom server) will need this ID later for requesting Google to send Push Notification to the user device. The user device will be identified using this particular registration ID. So your server needs to store that. You can have some sort of mapping of registration ID to some friendly name on your server side.

In short, you need a custom server to which you will send the registration id from the user device when it receives from Google. But, you don't need it for (.register) function.