谷歌GCM 1推送,创建2个通知而不是1

时间:2015-04-17 10:56:31

标签: android cordova push-notification google-cloud-messaging phonegap-plugins

当我运行脚本以使用简单消息推送通知时,这就是我在设备中获得的内容: (由于我的声誉,我无法发布图片,但它显示的是:2个通知,一个带有我的应用程序名称,另一个带有消息) 我的应用程序是用phonegap构建的。 Android版本5 Phonegap版本3.7.0 我使用php脚本通过我的服务器将通知推送到Android设备:

$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 个答案:

答案 0 :(得分:0)

可能有很多原因导致一条消息收到两条通知。但我的看法是,请检查以下内容:

  • 将整个邮件作为“标题”和“正文”发送到一个捆绑包中。
  • 检查此PHP脚本以确保您有类似的东西。

    include_once './GCM.php';
    
    $gcm = new GCM();
    
    $registatoin_ids = array($regId);
    $message = array("price" => $message);
    
    $result = $gcm->send_notification($registatoin_ids, $message);
    
    echo $result;
    }
    ?>
    
  • 确保您的Manifest中只有一个和一个广播接收器才能接收广播。