2013-07-18 17 views
1

我有GCMRegistrar問題,這裏是代碼:GCMRegistrar checkManifest crashses我的應用程序

// Make sure the device has the proper dependencies. 
GCMRegistrar.checkDevice(this); 
GCMRegistrar.checkManifest(this); <- this line is the problem (I suppose) 
regId = GCMRegistrar.getRegistrationId(this); 

當我把上面一行註釋的應用程序不會崩潰,但REGID是空的,當我嘗試使用這一行它使我的應用程序崩潰,我不知道爲什麼,所以我希望你能幫助我。 :)如果

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

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

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 

<permission 
    android:name="com.example.chattest1.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" /> 

<uses-permission android:name="com.example.chattest1.permission.C2D_MESSAGE" /> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.VIBRATE" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.chattest1.RegisAct" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.chattest1.Main" 
     android:label="@string/title_activity_regis" > 
    </activity> 
</application> 

</manifest> 
+0

使用LogCat檢查與您的崩潰相關的Java堆棧跟蹤。另請注意,'GCMRegistrar'已正式棄用 - Google要求您開始使用'GoogleCloudMessaging',而不是:https://developer.android.com/google/gcm/gs.html – CommonsWare

回答

1

checkManifest檢查你的清單包含GCM需要定義工作。 丟失東西時拋出IllegalStateException

就你而言,你錯過了一個廣播接收器,它可以接收來自GCM的消息。

GCMRegistrar.getRegistrationId(this)(返回本地存儲的註冊ID)只如果調用GCMRegistrar.register第一個將返回一個非空值。請注意,GCMRegistrar.register是非阻塞的,所以響應不會立即到達。

最後,根據CommonsWare的建議,GCMRegistrar已棄用,建議您改爲使用GoogleClassMessaging類。

相關問題