2011-07-09 61 views
0

[更新]
(當你讀我的問題,這是很好的瞭解)
我有一個小的編程錯誤,現在同類工作的錯誤的C2DM應用。但是在手機上的應用程序都收到了同樣的信息,從而有件事我忘了做C2DM爲什麼我的手機收到消息

[END更新]

我有一個C2DM的應用程序和服務器設置爲一個月,一切工作篦。 我有14個用戶/朋友註冊,並推動作品發現

當我運行下一版本的應用程序和服務器的另一臺計算機上創建沙箱時,我遇到了一些麻煩。

在沙箱上,我更改了應用程序的包名稱。
在我的手機上,我的兩個版本都安裝得很好,花花公子。
唯一的區別是沙箱版本應用程序正在與沙箱服務器通信(當然)。
爲什麼手機上的錯誤c2dm應用程序收到消息?

現在, 爲什麼非沙盒應用程序正在接收來自沙箱應用程序的消息?

對於像我這樣的業餘程序員來說,c2dm的文檔有時很難理解。
林困惑的:

public static final String EXTRA_APPLICATION_PENDING_INTENT = "app"; 

我應該寫在這裏包的名稱? 東西必須唯一標識這兩個應用程序的權利?

另一件我找不到答案/文件是registration_id。
我想一個手機只有一個registration_id,但可以有多個c2dm應用程序?
這是我的假設,很高興糾正我,如果我錯了。

如果問題出在我處理registration_id的方式或我發送推送消息的方式,我會感到困惑。不知道從哪裏開始?

[更新] ...

<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" 
     android:permission="com.google.android.c2dm.permission.SEND"> 
     <intent-filter> 
     <!-- Receive the actual message --> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      <category android:name="com.bent.blaster" /> 
     </intent-filter> 
     <intent-filter> 
     <!-- Receive the registration id --> 
      <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
      <category android:name="com.bent.blaster" /> 
     </intent-filter> 
</receiver> 

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
      package="com.bent.blaster" 
      android:versionCode="1" 
      android:versionName="0.52" 
      android:installLocation="preferExternal"> 
    <permission android:name="com.bent.blaster.permission.C2D_MESSAGE" android:protectionLevel="signature" />  
    <uses-permission android:name="com.bent.blaster.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />  
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
    <uses-sdk android:minSdkVersion="8" /> 
+0

@advantej感謝您在c2dm上的精彩博客。 – Erik

回答

0

我認爲我遇到的問題是因爲很短的時間內兩個應用程序都有相同的reg_id。當我24小時後卸載/重新安裝其中一個時,情況發生了變化。起初有點令人困惑,但在與Google團隊交談後,現在很清楚,一切都在進行中。感謝您的時間

0

什麼,我這裏寫我最初是從許多頁了但這樣做是對我最好的一個是http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html#example_server 在開始我看着谷歌I/O 2010年c2dm介紹,然後我看了這個不錯的演講http://marakana.com/forums/android/general/272.html,但終於有那連接了我所有需要使我的應用程序工作。

答案: 在您指定的接收器這樣的清單(這是應用程序標籤內的元素):

<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" 
     android:permission="com.google.android.c2dm.permission.SEND"> 
     <!-- Receive the actual message --> 
     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      <category android:name="de.vogella.android.c2dm" /> 
     </intent-filter> 
     <!-- Receive the registration id --> 
     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
      <category android:name="de.vogella.android.c2dm" /> 
     </intent-filter> 
    </receiver> 

通知類別標籤,我想你沒有指派您的包名或者此權限的那一個或者從缺少一個類別(這是明顯的根標籤內的元素):

<permission android:name="de.vogella.android.c2dm.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 

因爲你已經猜到了類別指定只有具有該包或子包的應用程序才能讀取c2dm消息 而android:protectionLevel =「簽名」指定您的c2dm消息受到簽名(即包)的保護。

有一個愉快的一天,我希望我幫助

+0

謝謝你的破敗。我已經完成了所有這些。我的設置看起來很像你的。即時更新我的​​問題。 – Erik

+0

好吧,我會等待更新;-) –

+0

我的應用程序和服務器一直工作正常月,但我不知道它是如何工作的詳細信息,我從來沒有想過這件事。 這樣的問題,從我從服務器使用電話reg.id發送推送信息時知道手機上的應用程序(如果有多少)應該是郵件的接收者。猜猜這個簽名是否正確?但我有difer。在我的兩個應用程序簽名,但當然忘記了 – Erik

0

當我的兩個應用程序,其中,接收相同的推沒
明白,每一個應用程序有它自己的registration_id。

我認爲他們在短時間內有相同的registration_id,直到我卸載/重新安裝他們。

相關問題