Android 未收到gcm推送消息
我正在使用android的GCM,这是androidhive.com上给出的一个示例代码。我可以在数据库中存储数据,但它不能推送数据。我不熟悉这个代码。所以,请同样帮助我。我的连接java文件和相应的php文件以及logcat消息如下所示--- 错误日志-Android 未收到gcm推送消息,android,google-cloud-messaging,Android,Google Cloud Messaging,我正在使用android的GCM,这是androidhive.com上给出的一个示例代码。我可以在数据库中存储数据,但它不能推送数据。我不熟悉这个代码。所以,请同样帮助我。我的连接java文件和相应的php文件以及logcat消息如下所示--- 错误日志- 11-07 16:55:42.306: E/Trace(1025): error opening trace file: No such file or directory (2) 11-07 16:55:43.146: D/libEGL(1
11-07 16:55:42.306: E/Trace(1025): error opening trace file: No such file or directory (2)
11-07 16:55:43.146: D/libEGL(1025): loaded /system/lib/egl/libEGL_emulation.so
11-07 16:55:43.166: D/(1025): HostConnection::get() New Host Connection established 0x2a1193e0, tid 1025
11-07 16:55:43.188: D/libEGL(1025): loaded /system/lib/egl/libGLESv1_CM_emulation.so
11-07 16:55:43.196: D/libEGL(1025): loaded /system/lib/egl/libGLESv2_emulation.so
11-07 16:55:43.337: W/EGL_emulation(1025): eglSurfaceAttrib not implemented
11-07 16:55:43.366: D/OpenGLRenderer(1025): Enabling debug mode 0
11-07 16:56:00.818: W/EGL_emulation(1025): eglSurfaceAttrib not implemented
11-07 16:56:04.207: E/SpannableStringBuilder(1025): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-07 16:56:04.207: E/SpannableStringBuilder(1025): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-07 16:56:21.786: W/EGL_emulation(1025): eglSurfaceAttrib not implemented
11-07 16:56:35.676: D/dalvikvm(1025): GC_CONCURRENT freed 238K, 4% free 8207K/8519K, paused 109ms+131ms, total 355ms
11-07 16:56:35.766: D/GCMRegistrar(1025): resetting backoff for com.androidhive.pushnotifications
11-07 16:56:35.806: V/GCMRegistrar(1025): Registering app com.androidhive.pushnotifications of senders 706448096441
11-07 16:56:35.886: I/Choreographer(1025): Skipped 34 frames! The application may be doing too much work on its main thread.
11-07 16:56:36.052: W/EGL_emulation(1025): eglSurfaceAttrib not implemented
11-07 16:56:37.826: V/GCMBroadcastReceiver(1025): onReceive: com.google.android.c2dm.intent.REGISTRATION
11-07 16:56:37.826: V/GCMBroadcastReceiver(1025): GCM IntentService class: com.androidhive.pushnotifications.GCMIntentService
11-07 16:56:37.846: V/GCMBaseIntentService(1025): Acquiring wakelock
11-07 16:56:37.876: V/GCMBaseIntentService(1025): Intent service name: GCMIntentService-706448096441-1
11-07 16:56:37.896: E/GCMRegistrar(1025): internal error: retry receiver class not set yet
11-07 16:56:37.896: V/GCMRegistrar(1025): Registering receiver
11-07 16:56:37.906: D/GCMBaseIntentService(1025): handleRegistration: registrationId = APA91bG-OslPbDcT_9iy0QTP7e_4ih9q95m6fyZJ4geYx1JojDhjmGUTy7aCvVMAq9vLXo31Kh5uP6YpenVc1zDOavhrX1gyayQAXevq8j1T0t1lf88Qm3ohz5mNQ7iC7kY52FG1hD8pgH5aSMGqb55xNGvCIuuFSbIJ3wmiGkpzHhYH2WEp-Q4, error = null, unregistered = null
11-07 16:56:37.906: D/GCMRegistrar(1025): resetting backoff for com.androidhive.pushnotifications
11-07 16:56:37.946: V/GCMRegistrar(1025): Saving regId on app version 1
11-07 16:56:37.978: I/GCMIntentService(1025): Device registered: regId = APA91bG-OslPbDcT_9iy0QTP7e_4ih9q95m6fyZJ4geYx1JojDhjmGUTy7aCvVMAq9vLXo31Kh5uP6YpenVc1zDOavhrX1gyayQAXevq8j1T0t1lf88Qm3ohz5mNQ7iC7kY52FG1hD8pgH5aSMGqb55xNGvCIuuFSbIJ3wmiGkpzHhYH2WEp-Q4
11-07 16:56:38.016: D/NAME(1025): radha
11-07 16:56:38.016: I/AndroidHive GCM(1025): registering device (regId = APA91bG-OslPbDcT_9iy0QTP7e_4ih9q95m6fyZJ4geYx1JojDhjmGUTy7aCvVMAq9vLXo31Kh5uP6YpenVc1zDOavhrX1gyayQAXevq8j1T0t1lf88Qm3ohz5mNQ7iC7kY52FG1hD8pgH5aSMGqb55xNGvCIuuFSbIJ3wmiGkpzHhYH2WEp-Q4)
11-07 16:56:38.016: D/AndroidHive GCM(1025): Attempt #1 to register
11-07 16:56:38.056: V/AndroidHive GCM(1025): Posting 'email=bhawna2909@gmail.com®Id=APA91bG-OslPbDcT_9iy0QTP7e_4ih9q95m6fyZJ4geYx1JojDhjmGUTy7aCvVMAq9vLXo31Kh5uP6YpenVc1zDOavhrX1gyayQAXevq8j1T0t1lf88Qm3ohz5mNQ7iC7kY52FG1hD8pgH5aSMGqb55xNGvCIuuFSbIJ3wmiGkpzHhYH2WEp-Q4&name=radha' to http://10.0.2.2/gcm_server_php/register.php
11-07 16:56:38.056: E/URL(1025): > http://10.0.2.2/gcm_server_php/register.php
11-07 16:56:39.057: V/GCMRegistrar(1025): Setting registeredOnServer status as true until 2012-11-14 16:56:39.057
11-07 16:56:39.166: V/GCMBaseIntentService(1025): Releasing wakelock
Java文件--
package com.androidhive.pushnotifications;
导入android.content.Context;
导入android.content.Intent;
公共最终类公用事业{
//在此处提供您的服务器注册url
静态最终字符串服务器\u URL=”http://10.0.2.2/gcm_server_php/register.php";
//谷歌项目id
静态最终字符串发送器\u ID=“70644809641”;
/**
*日志消息上使用的标记。
*/
静态最终字符串标记=“AndroidHive GCM”;
静态最终字符串显示\消息\操作=
“com.androidhive.pushnotifications.DISPLAY_消息”;
静态最终字符串EXTRA_MESSAGE=“MESSAGE”;
/**
*通知UI显示消息。
*
*此方法是在公共帮助器中定义的,因为两者都使用它
*用户界面和后台服务。
*
*@param context应用程序的上下文。
*@param要显示的消息。
*/
静态void displayMessage(上下文、字符串消息){
意图=新意图(显示消息动作);
intent.putExtra(额外消息,消息);
发送广播(意图);
}
}
PHP文件--
我也尝试了android hive教程,但没有成功,然后我又在谷歌上做了一些尝试,发现这对我来说很有效
假设您没有在php的else大括号中结束,那么回声$result显示了什么?您是否在响应中得到了多播,如开发文档所示:{“multicast_id”:6782339717028231855,“success”:0,“failure”:0,“canonical_id”:0,"…etcNo,它没有显示多播..echo$结果显示了什么?我们已经删除了echo$结果,现在它没有显示任何错误,但是推送通知没有收到。您需要将其放回。第一步是确定您的消息是否从PHP页面发送到GCM服务器。确定后,您可以进行调查e从GCM服务器到设备的阶段是否工作。
package com.androidhive.pushnotifications;
import android.content.Context;
import android.content.Intent;
public final class CommonUtilities {
// give your server registration url here
static final String SERVER_URL = "http://10.0.2.2/gcm_server_php/register.php";
// Google project id
static final String SENDER_ID = "706448096441";
/**
* Tag used on log messages.
*/
static final String TAG = "AndroidHive GCM";
static final String DISPLAY_MESSAGE_ACTION =
"com.androidhive.pushnotifications.DISPLAY_MESSAGE";
static final String EXTRA_MESSAGE = "message";
/**
* Notifies UI to display a message.
* <p>
* This method is defined in the common helper because it's used both by
* the UI and the background service.
*
* @param context application's context.
* @param message message to be displayed.
*/
static void displayMessage(Context context, String message) {
Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
intent.putExtra(EXTRA_MESSAGE, message);
context.sendBroadcast(intent);
}
}
<?php
// response json
$json = array();
/**
* Registering a user device
* Store reg id in users table
*/
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["regId"]))
{
$name = $_POST["name"];
$email = $_POST["email"];
$gcm_regid = $_POST["regId"];
// GCM Registration ID
// Store user details in db
include_once './db_functions.php';
include_once './GCM.php';
$db = new DB_Functions();
$gcm = new GCM();
$res = $db->storeUser($name, $email, $gcm_regid);
$registatoin_ids = array($gcm_regid);
$message = array("product" => "shirt");
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
}
else {
// user details missing
}
?>