Android的推送通知GCM通知、Android、GCM

2023-09-04 23:11:37 作者:我们总喜欢去修改自己的,让它更符合当下的心情及状态,下面整理

我的工作在Android GCM我的应用程序发送推送通知用户。而我下面这个教程

I am working on android GCM for my application to send push notification to users. And I am following this tutorial

http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

但在本教程它表明,我们可以发送推送通知到各个设备。但我想发送推送通知所有用户一次。那么,如何实现这种技术。

But in This tutorial its shown that we can send push notification to individual device. But I want to send push notification to all the users at once. So how can I implement this technique.

推荐答案

我已经遇到了同样的问题,解决了它。发送推送通知所有用户一次,你必须做所有你所提到的教程列出的东西。但是,你必须改变两个文件:的index.php send_message.php

I have already faced the same problem and solved it. To send push notification to all the users at once, you have to do all the things listed on the tutorial you've mentioned. But you have to change two files: index.php and send_message.php

的index.php

一个。使用以下内容替换JavaScript的code:

a. Replace the JavaScript code with the following:

$(document).ready(function(){

});
function sendToAll(){
    var data = $("#sendtoall").serialize();
    $("#sendtoall").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;
}

乙。更换体内标签的code以下的(跳过第一个五线):

b. Replace the code inside body tag with the following (skipping first five lines):

<div class="container">
    <h1>No of Devices Registered: <?php echo $no_of_users; ?></h1>
    <hr/>
    <ul class="devices">
        <?php
        if ($no_of_users > 0) {
            ?>
            <li>
                <form id="sendtoall" name="" method="post" onsubmit="return sendToAll()">
                    <div class="send_container">                               
                        <textarea rows="3" name="message" cols="25" class="txt_message" placeholder="Type message here"></textarea>
                        <?php
                        while ($row = mysql_fetch_array($users)) {
                        ?>
                        <input type="hidden" name="regId[]" value="<?php echo $row["gcm_regid"]; ?>"/>
                        <?php
                        }
                        ?>
                        <input type="submit" class="send_btn" value="Send To All" onclick=""/>
                    </div>
                </form>
            </li>
            <?php
        } else { ?>
            <li>
                No Users Registered Yet!
            </li>
        <?php } ?>
    </ul>
</div>
<div class="clear"></div>

send_message.php

替换行:

$registatoin_ids = array($regId);

$registatoin_ids = $regId;