【问题标题】:Google GCM 1 push, creates 2 notifications instead of 1Google GCM 1 推送,创建 2 个通知而不是 1 个
【发布时间】:2015-04-17 10:56:30
【问题描述】:

当我运行脚本来推送带有简单消息的通知时,这就是我在设备中得到的: (由于我的声誉,我无法发布图片,但它显示的是:2 条通知,1 条带有我的应用程序名称,1 条带有消息) 我的应用程序是用 phonegap 构建的。 安卓版本 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;

【问题讨论】:

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


    【解决方案1】:

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

    • 在一个 Bundle 中以“title”和“body”的形式发送整个消息。
    • 检查此 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;
      }
      ?>
      
    • 确保您的清单中只有一个广播接收器来接收广播。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-01
      • 2017-05-02
      相关资源
      最近更新 更多