向所有设备发送通知

时间:2014-12-17 05:19:17

标签: android push-notification google-cloud-messaging

我按照AndroidHive中的说明进行了操作,并且我成功了。但它只能让我向特定用户发送通知。我想一次发送给所有用户。我试图添加一个“循环”但它没有用。请帮我。 -update- 这是index.php

        function sendPushNotification(id){
            var data = $('form#'+id).serialize();
            $('form#'+id).unbind('submit');                
            $.ajax({
                url: "send_message.php",
                type: 'GET',
                data: data,
                beforeSend: function() {

                },
                success: function(data, textStatus, xhr) {
                      $('.txt_message').val("");
                },
                error: function(xhr, textStatus, errorThrown) {

                }
            });
            return false;
        }
</head>
<body>
    <?php
    include_once 'db_functions.php';
    $db = new DB_Functions();
    $users = $db->getAllUsers();
    if ($users != false)
        $no_of_users = mysql_num_rows($users);
    else
        $no_of_users = 0;
    ?>
    <div class="container">
        <h1>Đã có <?php echo $no_of_users; ?> người đăng ký nhận thông báo</h1>
        <hr/>
        <ul class="devices">
            <?php
            if ($no_of_users > 0) {
                ?>
                <?php
                while ($row = mysql_fetch_array($users)) {
                    ?>
                    <li>
                        <form id="<?php echo $row["id"] ?>" name="" method="post" onsubmit="return sendPushNotification('<?php echo $row["id"] ?>')">
                            <label>Tên: </label> <span><?php echo $row["name"] ?></span>
                            <div class="clear"></div>
                            <label>Lớp / Tổ:</label> <span><?php echo $row["email"] ?></span>
                            <div class="clear"></div>
                            <div class="send_container">                                
                                <textarea rows="3" name="message" cols="25" class="txt_message" placeholder="Nhập thông báo"></textarea>
                                <input type="hidden" name="regId" value="<?php echo $row["gcm_regid"] ?>"/>
                                <input type="submit" class="send_btn" value="Gửi đi" onclick=""/>
                            </div>
                        </form>
                    </li>
                <?php }
            } else { ?> 
                <li>
                    :)))
                </li>
            <?php } ?>
        </ul>
    </div>
</body>

和send.php

if (isset($_GET["regId"]) && isset($_GET["message"])) {
$regId = $_GET["regId"];
$message = $_GET["message"];

include_once './GCM.php';

$gcm = new GCM();

$registatoin_ids = array($regId);
$message = array("price" => $message);

$result = $gcm->send_notification($registatoin_ids, $message);

echo $result;

1 个答案:

答案 0 :(得分:0)

您可以传递注册ID数组

如果在代码中看到了什么

$ registatoin_ids = array($ gcm_regid1,$ gcm_regid2);

相关问题