2
votes

When i run the script to push a notification with a simple message this is what i get in my device: (i cannot post images because of my reputation but what it displays is: 2 notifications, one with the name of my app, and one with the message) My app is built with phonegap. Android version 5 Phonegap version 3.7.0 I use a php script to push notifications to android devices through my server:

$msg = array
(
    'message'   => 'test test test'

);

$fields = array
(
    'registration_ids'  => $registrationIds,
    'data'          => $msg
);

$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );

echo $result;
1

1 Answers

0
votes

There may be lot of reasons you are getting two notifications for one message. But my take is, Please check the following:

  • Send the whole message in one Bundle as "title" and "body".
  • Check this PHP script to make sure that you have something similar.

    include_once './GCM.php';
    
    $gcm = new GCM();
    
    $registatoin_ids = array($regId);
    $message = array("price" => $message);
    
    $result = $gcm->send_notification($registatoin_ids, $message);
    
    echo $result;
    }
    ?>
    
  • Make sure you have just one and one Broadcast receiver in your Manifest to receive the Broadcast.