GCM推送消息未收到 [英] gcm push messages are not received

查看:344
本文介绍了GCM推送消息未收到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Android的GCM,在androidhive.com.I给出一个样本code是能够将数据存储在数据库中,但它不是不能推的数据。我是新来这个code。所以请帮助我一样。我连接的Java文件,并与logcat的消息一起相应的PHP文件如下所示---

错误日志 -

  16 11-07:55:42.306:E /跟踪(1025):错误打开跟踪文件:没有这样的文件或目录(2)
11-07 16:55:43.146:D / libEGL(1025):加载/system/lib/egl/libEGL_emulation.so
11-07 16:55:43.166:D /(1025):HostConnection ::得到()新主机连接建立0x2a1193e0,TID 1025
11-07 16:55:43.188:D / libEGL(1025):加载/system/lib/egl/libGLESv1_CM_emulation.so
11-07 16:55:43.196:D / libEGL(1025):加载/system/lib/egl/libGLESv2_emulation.so
11-07 16:55:43.337:W / EGL_emulation(1025):eglSurfaceAttrib没有实现
11-07 16:55:43.366:D / OpenGLRenderer(1025):启用调试模式0
11-07 16:56:00.818:W / EGL_emulation(1025):eglSurfaceAttrib没有实现
11-07 16:56:04.207:E / SpannableStringBuilder(1025):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有长度为零
11-07 16:56:04.207:E / SpannableStringBuilder(1025):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有长度为零
11-07 16:56:21.786:W / EGL_emulation(1025):eglSurfaceAttrib没有实现
11-07 16:56:35.676:D / dalvikvm(1025):GC_CONCURRENT释放238K,4%免​​费8207K / 8519K,暂停109ms + 131ms,355ms总
11-07 16:56:35.766:D / GCMRegistrar(1025):为com.androidhive.pushnotifications重置退避
11-07 16:56:35.806:V / GCMRegistrar(1025):发件人的注册应用com.androidhive.pushnotifications 706448096441
11-07 16:56:35.886:I /编舞(1025):34跳过帧!该应用程序可能会做它的主线程的工作太多了。
11-07 16:56:36.052:W / EGL_emulation(1025):eglSurfaceAttrib没有实现
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类:com.androidhive.pushnotifications.GCMIntentService
11-07 16:56:37.846:V / GCMBaseIntentService(1025):获取激活锁定
11-07 16:56:37.876:V / GCMBaseIntentService(1025):意图服务名称:GCMIntentService-706448096441-1
11-07 16:56:37.896:E / GCMRegistrar(1025):内部错误:重试接收器类还没有设置
11-07 16:56:37.896:V / GCMRegistrar(1025):注册接收器
11-07 16:56:37.906:D / GCMBaseIntentService(1025):handleRegistration:registrationId = APA91bG-OslPbDcT_9iy0QTP7e_4ih9q95m6fyZJ4geYx1JojDhjmGUTy7aCvVMAq9vLXo31Kh5uP6YpenVc1zDOavhrX1gyayQAXevq8j1T0t1lf88Qm3ohz5mNQ7iC7kY52FG1hD8pgH5aSMGqb55xNGvCIuuFSbIJ3wmiGkpzHhYH2WEp-Q4,错误= NULL,未注册= NULL
11-07 16:56:37.906:D / GCMRegistrar(1025):为com.androidhive.pushnotifications重置退避
11-07 16:56:37.946:V / GCMRegistrar(1025):保存REGID应用版本1
11-07 16:56:37.978:I / GCMIntentService(1025):设备注册:REGID = APA91bG-OslPbDcT_9iy0QTP7e_4ih9q95m6fyZJ4geYx1JojDhjmGUTy7aCvVMAq9vLXo31Kh5uP6YpenVc1zDOavhrX1gyayQAXevq8j1T0t1lf88Qm3ohz5mNQ7iC7kY52FG1hD8pgH5aSMGqb55xNGvCIuuFSbIJ3wmiGkpzHhYH2WEp-Q4
11-07 16:56:38.016:D / NAME(1025):拉达
11-07 16:56:38.016:I / AndroidHive GCM(1025):注册设备(REGID = APA91bG-OslPbDcT_9iy0QTP7e_4ih9q95m6fyZJ4geYx1JojDhjmGUTy7aCvVMAq9vLXo31Kh5uP6YpenVc1zDOavhrX1gyayQAXevq8j1T0t1lf88Qm3ohz5mNQ7iC7kY52FG1hD8pgH5aSMGqb55xNGvCIuuFSbIJ3wmiGkpzHhYH2WEp-Q4)
11-07 16:56:38.016:D / AndroidHive GCM(1025):尝试#1注册
11-07 16:56:38.056:V / AndroidHive GCM(1025)发布'email=bhawna2909@gmail.com&regId=APA91bG-OslPbDcT_9iy0QTP7e_4ih9q95m6fyZJ4geYx1JojDhjmGUTy7aCvVMAq9vLXo31Kh5uP6YpenVc1zDOavhrX1gyayQAXevq8j1T0t1lf88Qm3ohz5mNQ7iC7kY52FG1hD8pgH5aSMGqb55xNGvCIuuFSbIJ3wmiGkpzHhYH2WEp-Q4&name=radha'到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):设置registeredOnServer地位真,直到2012年11月14日16:56:39.057
11-07 16:56:39.166:V / GCMBaseIntentService(1025):释放激活锁定

Java的文件 -

 包com.androidhive.pushnotifications;进口android.content.Context;
进口android.content.Intent;公共final类CommonUtilities {    //在这里给你的服务器注册网址
    静态最后弦乐SERVER_URL =htt​​p://10.0.2.2/gcm_server_php/register.php;    //谷歌项目编号
    静态最后弦乐SENDER_ID =706448096441;    / **
     *在日志消息中使用的标记。
     * /
    静态最后弦乐TAG =AndroidHive GCM    静态最后弦乐DISPLAY_MESSAGE_ACTION =
            com.androidhive.pushnotifications.DISPLAY_MESSAGE;    静态最后弦乐EXTRA_MESSAGE =消息;    / **
     *通知UI显示一条消息。
     *所述p为H.;
     *此方法在共同辅助限定,因为它是由使用两个
     *用户界面和后台服务。
     *
     * @参数范围内应用程序的上下文。
     *要显示@param消息消息。
     * /
    静态无效displayMessage(上下文的背景下,字符串消息){
        意向意图=新意图(DISPLAY_MESSAGE_ACTION);
        intent.putExtra(EXTRA_MESSAGE,消息);
        context.sendBroadcast(意向);
    }
}

PHP文件 -

 < PHP
//响应JSON
$ JSON =阵列();
/ ***注册用户设备在用户表*商店章ID* /如果(使用isset($ _ POST [名称])及和放大器;使用isset($ _ POST [电子邮件])及和放大器;使用isset($ _ POST [REGID]))
 {
    $名称= $ _ POST [名称];   $电子邮件= $ _ POST [电子邮件]; $ gcm_regid = $ _ POST [REGID];
// GCM注册ID//在数据库存储用户的细节include_once'./db_functions.php';    include_once'./GCM.php';
    $ DB =新DB_Functions();   $ GCM =新GCM();
    $解析度= $ DB-GT&; storeUser($名称,$电子邮件,$ gcm_regid);
    $ registatoin_ids =阵列($ gcm_regid);    $消息=阵列(产品=>中的衬衫);
    $结果= $ gcm-> send_notification($ registatoin_ids,$消息);
    回声$结果;
}
 其他{   //用户信息丢失}?>


解决方案

我也尝试过的Andr​​oid蜂巢的教程,但它并没有工作,然后就没有更多的一些谷歌,找到这个它为我工作。

<一个href=\"http://androidexample.com/Android_Push_Notifications_using_Google_Cloud_Messaging_GCM/index.php?view=article_discription&aid=119&aaid=139\" rel=\"nofollow\">http://androidexample.com/Android_Push_Notifications_using_Google_Cloud_Messaging_GCM/index.php?view=article_discription&aid=119&aaid=139

I am using GCM for android, a sample code given on androidhive.com.I am able to store data in a database but it is not not able to push data. I am new to this code. so please help me the same. My connection java file and corresponding php file along with the logcat messages is shown below---

Error log-

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&regId=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 file--

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 file--

<?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

}

?>

解决方案

I too tried the tutorial of android hive but it didn't worked then i did some more google and find this which worked for me.

http://androidexample.com/Android_Push_Notifications_using_Google_Cloud_Messaging_GCM/index.php?view=article_discription&aid=119&aaid=139

这篇关于GCM推送消息未收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆