1

由於標題指示在API 10仿真器上嘗試使用Google Cloud Messaging獲取令牌時出現TIMEOUT異常。我已經加入我的谷歌帳戶的設備上,經檢查發現「同步」爲ON時,還增加了在接收清單中的 <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>,仍然無法找出是什麼原因造成這樣的:Android GCM instanceID.getToken()在Gingerbread上引發TIMEOUT異常

11-25 17:35:00.896 29750-29774/com.example.alexis.myapplication W/InstanceID/Rpc: No response [email protected] 
11-25 17:35:00.896 29750-29774/com.example.alexis.myapplication E/MYAPP: TIMEOUT 

這裏是清單聲明權限:

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<permission android:name="com.example.alexis.myapplication.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
<uses-permission android:name="com.example.alexis.myapplication.permission.C2D_MESSAGE" /> 

<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 

和接收器:

<receiver 
     android:name="com.google.android.gms.gcm.GcmReceiver" 
     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.example.alexis.myapplication" /> 

     </intent-filter> 
    </receiver> 

任何幫助將高度讚賞。

注意:我在2.3.7上使用genymotion模擬器,我沒有硬件設備來測試。

+0

嘗試在這裏使用官方回購:https://github.com/google/gcm/tree/master/samples/android/gcm-demo – bjiang

+0

謝謝,事實證明,它沒有getToken因爲我使用模擬器。今天拿到了一個用於測試的硬件設備,並且如預期的那樣立即工作。 – Alex

+0

很高興聽到這個消息 – bjiang

回答

0

使用一個硬件設備,一切正常,所以這是模擬器的錯誤。