2012-09-11 55 views
2

我之前實施了一個GCM項目。我想現在創建一個新項目,我需要一個新的項目ID,但我現在無法註冊。是關於項目ID嗎?或者我可以使用以前的項目ID?Android GCM-清單文件和註冊

而最後一個問題:

<category android:name="my_app_package" /> 

<permission android:name="my_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
<uses-permission android:name="my_app_package.permission.C2D_MESSAGE" /> 

什麼是應用程序包的名稱?它在清單文件的頂部嗎?還是它包含GCM java頁面?

回答

0

首先,如果你想再次註冊 - 你應該取消註冊。

應用程序包需要gcm服務。 註冊您的GCMBroadcastReceiver。

<receiver 
      android:name="com.google.android.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="my_app_package" /> 
      </intent-filter> 
     </receiver> 
2
<?xml version="1.0" encoding="utf-8"?> 

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.demo.demo" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <!-- GCM requires Android SDK version 2.2 (API level 8) or above. --> 
    <!-- The targetSdkVersion is optional, but it's always a good practice 
     to target higher versions. --> 
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/> 

    <!-- 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.ketan.demo.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 
    <uses-permission 
     android:name="com.ketan.demo.permission.C2D_MESSAGE" /> 

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

    <!-- Main activity. --> 
    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name="com.ketan.demo.DemoActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <!-- 
      BroadcastReceiver that will receive intents from GCM 
      services and handle them to the custom IntentService. 

      The com.google.android.c2dm.permission.SEND permission is necessary 
      so only GCM services can send data messages for the app. 
     --> 
     <receiver 
      android:name="com.google.android.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.ketan.demo" /> 
      </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=".GCMIntentService" /> 
    </application> 

</manifest> 

我已經實現了GCM所以參考清單文件爲。

+0

您的pkg名稱與android:name =「com.ketan.demo.permission.C2D_MESSAGE」不匹配。 –

+1

@GooGLE和Vineet Shukla我明白我的包名是不同的。我寫清單文件爲你的,但我仍然獲得空註冊ID。我還能做些什麼呢? – user1451549

+0

那麼你必須粘貼代碼,以便我可以看到你實際上做了什麼 – Google

0

是的,你可以使用以前的專案編號,但是當你發送通知使用專案編號也可以接收通知的其他應用程序,如果你以前註冊。

您應該可以使用新的項目ID。也許你做錯了什麼,再次檢查。

關於第二個問題,app_package是應用程序的主包。

+1

謝謝你,但我仍然得到空的註冊ID,我無法註冊,我還能做什麼? – user1451549

+0

在這裏粘貼你的代碼,以便我們可以控制它。 –

+1

GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(本);字符串regId = GCMRegistrar.getRegistrationId(this); if(regId.equals(「」)){GCMRegistrar.register(this,SENDER_ID); }其他{MyLog.log(「已經註冊」); } regId = GCMRegistrar.getRegistrationId(this); MyLog.log(「register id =」+ regId); System.out中。println(「Get Reg ID:」+ GCMRegistrar.getRegistrationId(this)); – user1451549

0

如果你沒有得到來自的主要原因registration.one響應您的清單文件沒有正確配置...特別是給「包名」(你喜歡com.xxx.yyy應用程序包的名稱)在並正確。