簡體   English   中英

未收到gcm推送消息

[英]gcm push messages are not received

我正在使用GCM for android,這是在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(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文件-

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文件-

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

}

?>

我也嘗試過android hive的教程,但是它沒有用,然后我做了更多的google並找到了對我有用的。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM