Android google云消息示例不工作 [英] Android google cloud messaging sample not working

查看:296
本文介绍了Android google云消息示例不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照此处的教程 http://developer.android.com/google/gcm /gs.html ,以便设置GCM。
当前正在尝试注册设备的过程。
然而,由于某种原因,应用程序总是似乎崩溃
gcm = GoogleCloudMessaging.getInstance(this);

Im following the tutorial here http://developer.android.com/google/gcm/gs.html in order to setup GCM. Im currently in the process of trying to register the device. However, for some reason, the application always seems to crash at gcm = GoogleCloudMessaging.getInstance(this);

stacktrace似乎指向以下内容:
06-18 13:42:20.909:I / dalvikvm(11613):找不到方法com。 google.android.gms.gcm.GoogleCloudMessaging.getInstance,从方法pushNotification.PushNotification $ 1.run引用

The stacktrace seems to point at the following: 06-18 13:42:20.909: I/dalvikvm(11613): Could not find method com.google.android.gms.gcm.GoogleCloudMessaging.getInstance, referenced from method pushNotification.PushNotification$1.run

到目前为止的示例

public PushNotification(Context c, Activity activity)
{
    context = c;
    this.activity = activity;
    regid = getRegistrationId(context);

    if (regid.length() == 0) {
        Log.d("IN PUSHNOTIFICATION ","NOT REGISTERED. REGISTERING NOW.....");
        registerBackground();
    }
    Log.d("IN PUSHNOTIFICATION ","REGISTRATION COMPLETE.....");
    Log.d("IN PUSHNOTIFICATION ","REGISTRATION ID IS: " + regid);
    gcm = GoogleCloudMessaging.getInstance(activity); //never reaches this code

}

private void registerBackground() {

    Thread thread = new Thread(new Runnable()
    {
        public void run()
        {
            String msg = "";
            try {
                if (gcm == null) {
                    Log.d("IN PUSHNOTIFICATION", "IN BACKGROUND. gcm == NULL");
                    gcm = GoogleCloudMessaging.getInstance(context);
                    Log.d("IN PUSHNOTIFICATION", "IN BACKGROUND. AFTER gcm.GETINSTANCE");
                }
                Log.d("IN PUSHNOTIFICATION", "IN BACKGROUND. BEFORE gcm.register");
                regid = gcm.register(SENDER_ID);
                msg = "Device registered, registration id=" + regid;
                Log.d("IN PUSHNOTIFICATION", "IN BACKGROUND. regid == " + regid);
                // You should send the registration ID to your server over HTTP,
                // so it can use GCM/HTTP or CCS to send messages to your app.

                // For this demo: we don't need to send it because the device
                // will send upstream messages to a server that echo back the message
                // using the 'from' address in the message.

                // Save the regid - no need to register again.
                setRegistrationId(context, regid);
            } catch (IOException ex) {
                Log.d("IN PUSHNOTIFICATION", "IN BACKGROUND. EXCEPTION ERROR ERROR: ex = " + ex.getMessage());
                msg = "Error :" + ex.getMessage();
            }
        }
    }
    );
    thread.start();
}

这里是完整的stacktrace

Here is the full stacktrace


06-18 13:42:20.909:D / IN PUSHNOTIFICATION(11613):未注册。
现在注册..... 06-18 13:42:20.909:I / dalvikvm(11613):无法
查找方法
com.google.android.gms.gcm.GoogleCloudMessaging .getInstance,
从方法pushNotification.PushNotification引用$ 1.run 06-18
13:42:20.909:W / dalvikvm(11613):VFY:无法解析静态方法
5967:Lcom /google/android/gms/gcm/GoogleCloudMessaging;.getInstance
(Landroid / content / Context;)Lcom / google / android / gms / gcm / GoogleCloudMessaging;
06-18 13:42:20.909:D / dalvikvm(11613):VFY:将操作码0x71替换为
0x0015 06-18 13:42:20.909:I / dalvikvm方法
com.google.android.gms.gcm.GoogleCloudMessaging.register,引用
从方法pushNotification.PushNotification $ 1.run 06-18
13:42:20.909:W / dalvikvm ):VFY:无法解析虚拟方法
5969:Lcom / google / android / gms / gcm / GoogleCloudMessaging; .register
([Ljava / lang / String;)Ljava / lang / String; 06-18 13:42:20.909:
D / dalvikvm(11613):VFY:将操作码0x6e替换为0x0039 06-18
13:42:20.909:D / IN PUSHNOTIFICATION(11613):注册完成.....
06-18 13:42:20.909:D / IN PUSHNOTIFICATION(11613):注册ID:
06-18 13:42:20.909:D / AndroidRuntime关闭VM 06-18
13:42:20.909:W / dalvikvm(11613):threadid = 1:退出线程
未捕获异常(组= 0x2b542210)06-18 13:42:20.909: D / IN
PUSHNOTIFICATION(11613):IN背景。 gcm == NULL 06-18
13:42:20.909:W / dalvikvm(11613):threadid = 20:线程退出
未捕获异常(组= 0x2b542210)06-18 13:42:20.909 :
I /过程(11613):发送信号。 PID:11613 SIG:9 06-18
13:42:20.919:I / ActivityManager(278):进程com.gotoohlala(pid
11613)已死。

06-18 13:42:20.909: D/IN PUSHNOTIFICATION(11613): NOT REGISTERED. REGISTERING NOW..... 06-18 13:42:20.909: I/dalvikvm(11613): Could not find method com.google.android.gms.gcm.GoogleCloudMessaging.getInstance, referenced from method pushNotification.PushNotification$1.run 06-18 13:42:20.909: W/dalvikvm(11613): VFY: unable to resolve static method 5967: Lcom/google/android/gms/gcm/GoogleCloudMessaging;.getInstance (Landroid/content/Context;)Lcom/google/android/gms/gcm/GoogleCloudMessaging; 06-18 13:42:20.909: D/dalvikvm(11613): VFY: replacing opcode 0x71 at 0x0015 06-18 13:42:20.909: I/dalvikvm(11613): Could not find method com.google.android.gms.gcm.GoogleCloudMessaging.register, referenced from method pushNotification.PushNotification$1.run 06-18 13:42:20.909: W/dalvikvm(11613): VFY: unable to resolve virtual method 5969: Lcom/google/android/gms/gcm/GoogleCloudMessaging;.register ([Ljava/lang/String;)Ljava/lang/String; 06-18 13:42:20.909: D/dalvikvm(11613): VFY: replacing opcode 0x6e at 0x0039 06-18 13:42:20.909: D/IN PUSHNOTIFICATION(11613): REGISTRATION COMPLETE..... 06-18 13:42:20.909: D/IN PUSHNOTIFICATION(11613): REGISTRATION ID IS: 06-18 13:42:20.909: D/AndroidRuntime(11613): Shutting down VM 06-18 13:42:20.909: W/dalvikvm(11613): threadid=1: thread exiting with uncaught exception (group=0x2b542210) 06-18 13:42:20.909: D/IN PUSHNOTIFICATION(11613): IN BACKGROUND. gcm == NULL 06-18 13:42:20.909: W/dalvikvm(11613): threadid=20: thread exiting with uncaught exception (group=0x2b542210) 06-18 13:42:20.909: I/Process(11613): Sending signal. PID: 11613 SIG: 9 06-18 13:42:20.919: I/ActivityManager(278): Process com.gotoohlala (pid 11613) has died.


推荐答案

我解决了这个问题。
虽然我链接到google-play-services_lib项目,我还必须将jar文件google-play-services_lib.jar添加到项目中。

I solved the problem. Although I was linking to google-play-services_lib project, I also had to add the jar file, google-play-services_lib.jar into the project.

这篇关于Android google云消息示例不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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