2012-08-13 76 views
0

我正在嘗試在我的android應用程序中集成G​​SM。我能夠通過該演示使用我的Api密鑰和Sender_id運行GCM-Client-demo應用和註冊設備,但是當我在我的應用中使用相同的代碼時,我無法使用GCM註冊設備。在android中註冊GCM的應用程序

我在日誌貓得到的錯誤是。

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> 

誰能告訴我我在做什麼錯誤?

回答

5

請更換(以menifest)

機器人:名字= 「view.GCMIntentService」代碼這個機器人:名字= 「GCMIntentService」,把GCMIntentService在同一個包「com.demo。 demogcm」

+0

謝謝..它的工作.. – Piyush 2012-08-13 06:33:40

4

您也可以使用此包和類名:<service android:name=".view.GCMIntentService" />但額外魔法

This intent service will be called by the GCMBroadcastReceiver (which is is provided by GCM library), as shown in the next step. It must be a subclass of com.google.android.gcm.GCMBaseIntentService, must contain a public constructor, and should be named my_app_package.GCMIntentService (unless you use a subclass of GCMBroadcastReceiver that overrides the method used to name the service).

這是如何工作的,你可以看到here

+1

非常有幫助的鏈接。試圖找出這一點失去了一天:(。+1 – 2014-02-27 10:03:12