Upstream message to server app

后端 未结 3 1148
死守一世寂寞
死守一世寂寞 2021-01-07 05:01

I have successfuly send data from php server page to android client with JAXL..

I have read carefully the guide of Google Cloud Message Offical website.. For Upstrea

3条回答
  •  广开言路
    2021-01-07 05:43

    Here is how I manage to upstream message...

    First get JAXL

    put it on your apache execute directory...

    create new php script file...

     '/*Write sender ID here*/@gcm.googleapis.com',
        'pass' => 'Write here your GCM apı key',
        'host' => 'gcm-preprod.googleapis.com',
        'port' => 5236,
       'strict' => false,
        'force_tls' => true,
        'log_level' => JAXL_DEBUG,
        'auth_type' => 'PLAIN',
        'protocol' => 'tls',
         'ssl' => TRUE,
        'log_path'=> 'ex.txt'  /*This create text file to comminication between gcm and your server*/
    ));
    
    $client->add_cb('on_message_stanza', function($msg) {
     echo 'now what!!';
     });
    
     $client->add_cb('on_auth_success', function() {
     echo 'it should';
    //Here is for sending downstream msg
      }); 
    
     $client->add_cb('on_error_message',function()
     {
     global $client;
     echo 'error
    '; _info('got on_error_message cb jid'.$client->full_jid->to_string()); }); $client->start(); ?>

    On android part, after you did integrate with GCM, A button with inside click listener

    String msg = "";
                            try {
                                Bundle data = new Bundle();
                                data.putString("my_message", "Hello World");
                                data.putString("my_action", "SAY_HELLO");
                                String id = Integer.toString(incrementAndGet());
                                gcm.send( "/*Write here sender ID*/"+ "@gcm.googleapis.com", id, data);
                                msg = "Sent message";
                            } catch (IOException ex) {
                                msg = "Error :" + ex.getMessage();
                            }
                            Log.d(msg,"-------------");
    

    Then, execute your php script, that writed above, then click button in order to send upstream msg, look ex.txt that jaxl created, you will see "Hello World" msg that sent by app

提交回复
热议问题