php - Success:1 still no notification in android -


i trying send push notification through gcm getting:

{   "multicast_id":4793018731783267982,   "success":1,   "failure":0,   "canonical_ids":0,   "results": [     { "message_id":"0:1452928098906665%a69ccee8f9fd7ecd" }   ] } 

but still no notification coming. here code:

//index.php code   $app->get( '/notify',function () use($app)          {                    $response = array ();                     $regid="device registration id";   //hard coded                     $message="hi everyone.this notify you" ;                     $registatoin_ids = array($regid);                     $message = array("price" => $message);                     $db = new dbhandler ();                     $result = $db->send_notification($registatoin_ids, $message);                     echorespnse ( 200, $result);              } );  //dbhandler code   public function send_notification($registatoin_ids, $message) {       $url = 'https://android.googleapis.com/gcm/send';      $fields = array(         'registration_ids' => $registatoin_ids,         'data' => $message,     );      $headers = array(         'authorization: key=aizasybyr3xutkhb-ozsntlqqlwnqslbzqxuwb0',  //server key          'content-type: application/json'     );     $ch = curl_init();      curl_setopt($ch, curlopt_url, $url);      curl_setopt($ch, curlopt_post, true);     curl_setopt($ch, curlopt_httpheader, $headers);     curl_setopt($ch, curlopt_returntransfer, true);      // disabling ssl certificate support temporarly     curl_setopt($ch, curlopt_ssl_verifypeer, false);      curl_setopt($ch, curlopt_postfields, json_encode($fields));      // execute post     $result = curl_exec($ch);     if ($result === false) {         die('curl failed: ' . curl_error($ch));     }      // close connection     curl_close($ch);     return $result; } 

note:i running api directly advanced rest client instead of android device.i getting success in response no notification on device reg_id have hard coded here.please help

edit================= have written code on android end:

if (checkplayservices())  {     gcm = googlecloudmessaging.getinstance(this);      if (regid.isempty())     {         new register().execute();     }     else     {         log.i("hello", "no valid google play services apk found.");     } }  public class register extends asynctask<void, integer, string> {      @override     protected void onpreexecute() {         super.onpreexecute();     }      @override     protected string doinbackground(void... params) {          string msg = "";          try           {               if (gcm == null)                {                    gcm = googlecloudmessaging.getinstance(getapplicationcontext());               }               regid = gcm.register(appconst.sender_id);                             log.i("hello", "current device's registration id is: "+regid);               }           catch (ioexception ex)           {              msg = "error :" + ex.getmessage();          }          return null;     }      @override     protected void onpostexecute(string result) {         super.onpostexecute(result);     } } 

in mainfest have added:

     <receiver         android:name=".gcmbroadcastreceiver"         android:permission="com.google.android.c2dm.permission.send"          >         <intent-filter>             <action android:name="com.google.android.c2dm.intent.receive" />             <category android:name="com.example" />         </intent-filter>      </receiver> 

handle notification on android device:

  @override  public void onmessagereceived(string from, bundle data) {    string message = data.getstring("message");    log.d(tag, "from: " + from);    log.d(tag, "message: " + message);    // handle received message here.  } 

for more info visit : https://developers.google.com/cloud-messaging/


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -