Managing the GCM number on the server

I found out about the GCM server today. Reading the content in the developer.android.com GCM section, I still don't know how to manage the registration ID on a third-party server. I understand:

  • An Android app can register and unregister its ID from the GCM server.
  • The server side can send messages to devices using a registration identifier and
    server.

So, how can I get the device registration ID from the GCM server? Do I need to directly access Android devices?

Thank you for your advice.

+6
source share
3 answers

The best place to learn basic information is here at developer.android.com

You will see this sample code in your tutorial:

/** * Registers the application with GCM servers asynchronously. * <p> * Stores the registration ID and app versionCode in the application's * shared preferences. */ private void registerInBackground() { new AsyncTask() { @Override protected String doInBackground(Void... params) { String msg = ""; try { if (gcm == null) { gcm = GoogleCloudMessaging.getInstance(context); } regid = gcm.register(SENDER_ID); msg = "Device registered, registration ID=" + regid; // 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. // The request to your server should be authenticated if your app // is using accounts. 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 registration ID - 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; } @Override protected void onPostExecute(String msg) { mDisplay.append(msg + "\n"); } }.execute(null, null, null); ... } 

If I understand correctly, you are confused about how to get the GCM RegistrationId to implement your server. You can do this in the sendRegistrationIdToBackend() method, which you define.

You need to create an endpoint to receive a POST request so that each device sends its registration ID as soon as it receives it from GCM. Then your server implementation will know about all the devices on which your application is installed and registered in GCM.

NOTE. One thing you might want to keep an eye on is not creating duplicate login identifiers if the device finishes placing its login ID twice or the user uninstalls and then reinstalls the application, but GCM gives them the same login ID with which you can encounter duplicates stored in your database on the server. If this happens, and you want to send push to all your users, then some of your users may receive several push notifications, depending on the number of duplicates in the database.

+4
source

First of all, you will not receive a registration number from the GCM server. You will receive Project Id and App Key from the Google Developer Console . You need to create a registration identifier using your client application . You must write some codes to create a registration identifier. You can follow this link . Here he was explained very well.

+1
source

You need to follow these steps to get gcm ID from Android device. Each device will have a unique gcm identifier for each application.

0
source

Source: https://habr.com/ru/post/983625/


All Articles