简体   繁体   中英

how to target my xmpp server using GCM API

I am trying to understand GCM from the developer android site. I have implemented the client side android app following the instructions at http://developer.android.com/google/gcm/client.html . The code i used is downloaded from https://code.google.com/p/gcm/ as they have mentioned. The GCM registration function works perfectly on my phone.

Now the problem is, no where in the android app code do i see a place to mention my xmpp based app server name. So if i don't mention my server name, how will the message go to my server? i am confused as to how will my app interact with my server. The exact code that sends the message from the android app to the server is :

// Send an upstream message.
public void onClick(final View view) {

    if (view == findViewById(R.id.send)) {
        new AsyncTask<Void, Void, String>() {
            @Override
            protected String doInBackground(Void... params) {
                String msg = "";
                try {
                    Bundle data = new Bundle();
                    data.putString("my_message", "Hello World");
                    data.putString("my_action", "com.google.android.gcm.demo.app.ECHO_NOW");
                    String id = Integer.toString(msgId.incrementAndGet());
                    gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data);
                    msg = "Sent message";
                } catch (IOException ex) {
                    msg = "Error :" + ex.getMessage();
                }
                return msg;
            }

            @Override
            protected void onPostExecute(String msg) {
                mDisplay.append(msg + "\n");
            }
        }.execute(null, null, null);
    } else if (view == findViewById(R.id.clear)) {
        mDisplay.setText("");
    }
}

When you send a device to cloud message from your app to your server you use the following call :

gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data);

The GCM CCS server identifies your server by the SENDER_ID (since your server uses that SENDER_ID when establishing the XMPP connection with the GCM CCS server).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM