我正在尝试为Android设置简单的推送通知。但是它从一开始就消失了。我正在追踪this tutorial
在我也尝试过google start up guide
但是问题是我无法将我的应用程序注册到我的Google服务。我已启用Google云消息传递。我的代码是:

   try{
    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);
    String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) {
      GCMRegistrar.register(this, "SENDER ID");
      Log.v("Registration", "new registration");// Note: get the sender id from configuration.
      regId = GCMRegistrar.getRegistrationId(this);
      Log.v("Registration", "Already registered, regId: " + regId);
    } else {
      Log.v("Registration", "Already registered, regId: " + regId);
    }
    }
    catch(Exception e){
        String a=e.toString();
        Log.v(a,a);
    }


一切正常,但是什么也没有发生,在此功能完成后,我的应用程序强制关闭。对于发件人ID,我使用google。(在链接末尾)中的号码。

因此,似乎没有错误,只是我的应用程序在关闭后没有注册。
还有一件有趣的事。当我在手机上调试该应用程序时,它将运行,但是当我在模拟器上启动该应用程序时,它将强制关闭。

最佳答案

终于找到了解决方法:d

问题是我将GCMIntentService命名为错误,然后将其命名为GcmIntentService,然后全部移至appart:S

因此,如果另一个像我这样的傻瓜遇到这个问题,我会发布此答案...

关于android - 在Android上启动推送通知GCM,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12246130/

10-12 00:39
查看更多