Android的推送通知GCM [英] Android push notification GCM
问题描述
我的工作在Android GCM我的应用程序发送推送通知用户。而我下面这个教程
I am working on android GCM for my application to send push notification to users. And I am following this tutorial
<一个href="http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/" rel="nofollow">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;
这篇关于Android的推送通知GCM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!