在android中注册GCM应用程序

在android中注册GCM应用程序,android,google-cloud-messaging,Android,Google Cloud Messaging,我正在尝试将GSM集成到我的android应用程序中。我可以使用Api密钥和发送者id运行GCM客户端演示应用程序并通过该演示注册设备,但当我在应用程序中使用相同的代码时,我无法向GCM注册设备 我在log cat中得到的错误是 08-13 11:24:34.787: W/ActivityManager(2465): Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTRATION cat=[com.

我正在尝试将GSM集成到我的android应用程序中。我可以使用Api密钥和发送者id运行GCM客户端演示应用程序并通过该演示注册设备,但当我在应用程序中使用相同的代码时,我无法向GCM注册设备

我在log cat中得到的错误是

08-13 11:24:34.787: W/ActivityManager(2465): Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTRATION cat=[com.demo.demogcm] cmp=com.demo.demogcm/.GCMIntentService (has extras) }: not found
我的清单文件

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!--
 Creates a custom permission so only this app can receive its messages.

 NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
       where PACKAGE is the application's package name.
-->
<permission
    android:name="com.demo.demogcm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission
    android:name="com.demo.demogcm.permission.C2D_MESSAGE" />

<!-- This app has permission to register and receive data message. -->
<uses-permission
    android:name="com.google.android.c2dm.permission.RECEIVE" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".view.DemoActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <receiver
        android:name="com.demo.demogcm.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.demo.demogcm" />
        </intent-filter>
    </receiver>

    <!--
      Application-specific subclass of GCMBaseIntentService that will
      handle received messages.

      By default, it must be named .GCMIntentService, unless the
      application uses a custom BroadcastReceiver that redefines its name.
    -->
    <service android:name=".view.GCMIntentService" />
</application>

有人能告诉我我犯了什么错误吗?

请在menifest中替换


android:name=.view.gcminentservice代码使用此android:name=.gcminentservice并将gcminentservice放在同一个包com.demo.demogcm中

您也可以使用此包和类名:但具有额外的魔力

此意向服务将由GCM库提供的GCMBroadcastReceiver调用,如下一步所示。它必须是com.google.android.gcm.GCMBaseIntentService的子类,必须包含公共构造函数,并且应命名为my_app_package.gcminentService,除非使用gcmbroadcasreceiver的子类重写用于命名服务的方法


您可以看到这是如何工作的。

非常有用的链接。花了一天的时间试图弄明白这一点:+1.