[英]Android C2DM: Problems to receive message in device
當我嘗試在設備中接收消息時遇到問題,但是一切正常,但是當我嘗試收不到消息時,卻遇到了問題:
id = 0:1319039498507602%b50b7d2400000031
來自https://android.apis.google.com/c2dm/send
這意味着消息已發送,不是嗎?
但我無法在設備中接收它。
有人可以幫助我嗎?
提前致謝。
編輯:我的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="clouders.com" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="clouders.com.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission
android:name="clouders.com.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".C2DMClientActivity" 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=".C2DMRegistrationReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"></action>
<category android:name="clouders.com" />
</intent-filter>
</receiver>
<receiver android:name=".C2DMMessageReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"></action>
<category android:name="clouders.com" />
</intent-filter>
</receiver>
<activity android:name="RegistrationResultActivity"></activity>
<activity android:name="MessageReceivedActivity"></activity>
</application>
</manifest>
根據可能的響應代碼列表: http : //code.google.com/android/c2dm/#server ,我相信您已使用google c2dm服務注冊了正確發送郵件的服務器,並且已使用了正確的身份驗證密鑰android手機的服務器和注冊ID, 因此google c2dm收到了消息,並向您發送了響應代碼200和id = 0:1319039498507602%b50b7d2400000031作為http響應內容,其中0:1319039498507602%b50b7d2400000031是已發送ID消息 。 我不知道您是否找到了解決方案,但是我建議按順序建議以下故障排除/調試機制,因為它可能會對其他人有所幫助:
1)在您對c2dm服務器的https請求中,message / payload參數是什么,因為在電話上進行調試時將需要此參數
2)確保您在手機Eggmail上登錄了Google帳戶。 您可以在手機的設置>帳戶和同步下執行此操作。
3)確保設備/電話已注冊,並且服務器正在使用電話上當前的注冊ID。 您可以檢查一下,但是記錄您注冊時的響應。 實際上,即使電話上的注冊ID發生了變化,服務器也應該能夠通過c2dm到達電話,但是請確保三端確認,在兩端使用相同的密碼。 同樣,出於注冊Android設備的意圖,請使用用於注冊c2dm的服務器的電子郵件作為發件人參數。
4)記錄來自c2dm的傳入消息。 我看到您有一個C2DMMessageReceiver類。 你可以在那里做。 這樣,您可以從服務器看到有效負載參數。 您也可以在消息以有效內容為內容到達時創建通知。 您也可以在Android上使用Toast快速顯示。
希望所有這些幫助。
您如何設置第三方服務器(基於C2DM-sharp或PHP)? 我將通過與google chrome-to-phone之類的示例進行比較來驗證客戶端代碼。 還要確保您注冊的C2DM電子郵件地址和密碼正確無誤。
您是否檢查過編碼問題? 您的ID似乎已編碼(我的意思是%b50嗎?)。
您從https://android.apis.google.com/c2dm/send獲得的ID是消息ID。 在評論中,您發布了與注冊ID相同的ID? 這應該不一樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.