2014-02-09 42 views
1

我已使用Freshplanet ANE爲推送通知創建了一個Flash CS6 AIR for Android應用程序。一切似乎都在工作,但我仍然沒有收到我的設備上的通知。使用GCM,Freshplanet ANE,Flash Professional CS6和VB.NET推送通知

這裏是我的Flash CS6代碼:

import com.freshplanet.nativeExtensions.PushNotification; 
import com.freshplanet.nativeExtensions.PushNotificationEvent; 

txtMsg.text = 'starting..'; 

var push:PushNotification = PushNotification.getInstance(); 
if (push.isPushNotificationSupported) { 
    push.registerForPushNotification("XXXXXXXXXXXXX"); //Google project ID 
} 

push.addEventListener(PushNotificationEvent.PERMISSION_GIVEN_WITH_TOKEN_EVENT, onRegistered); 
push.addEventListener(PushNotificationEvent.PERMISSION_REFUSED_EVENT, onRefused); 

function onRegistered(event:PushNotificationEvent):void 
{ 
    txtMsg.appendText("Registered with registration id:" + event.token); 
} 
function onRefused(event:PushNotificationEvent):void 
{ 
    txtMsg.appendText("Refused:" + event.errorMessage); 
} 

此代碼似乎工作,因爲當我啓動我的應用我的設備上,我txtMsg字段顯示event.token。一個長字符串,包含我猜測是唯一的設備ID。

我的Android清單如下: `

<android> 
    <manifestAdditions> 
     <![CDATA[<manifest> 
       <uses-permission android:name="android.permission.INTERNET"/> 
       <uses-permission android:name="android.permission.WAKE_LOCK"/> 
       <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
       <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 
       <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
       <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
       <uses-permission android:name="air.it.test.PushTest2.permission.C2D_MESSAGE" /> 
       <permission android:name="air.it.test.PushTest2.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
       <application> 
        <activity android:name="air.it.test.PushTest2"></activity> 
        <receiver android:name="com.freshplanet.nativeExtensions.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="air.it.test.PushTest2" /> 
         <intent-filter> 
         </intent-filter> 
          <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
          <category android:name="air.it.test.PushTest2" /> 
         </intent-filter> 
        </receiver> 
        <service android:name="com.freshplanet.nativeExtensions.LocalNotificationService"/> 
        <receiver android:name="com.freshplanet.nativeExtensions.LocalBroadcastReceiver" android:process=":remote"></receiver> 
       </application> 
</manifest>]]> 
    </manifestAdditions> 
    </android> 
    <extensions> 
    <extensionID>com.freshplanet.AirPushNotification</extensionID> 
    </extensions> 

`

這是我的VB.NET服務器應用程序發送該消息與上述接收的令牌設備。

Dim regId As String = "XXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXX" device token id 
    Dim MessageText As String = "Hope this works" 
    Dim applicationID As String = "APP ID" 'received from Google API console as the Key for server applications 
    Dim result As String = "" 
    Dim SENDER_ID As String = "XXXXXXXXXXXXX" 'same ID used in my actionscript file above - Google project ID 
    Dim httpWebRequest As WebRequest = WebRequest.Create("https://android.googleapis.com/gcm/send") 

    httpWebRequest.ContentType = "application/json" 
    httpWebRequest.Method = "POST" 
    httpWebRequest.Headers.Add(String.Format("Authorization: key={0}", applicationID)) 
    httpWebRequest.Headers.Add(String.Format("Sender: key={0}", SENDER_ID)) 

    Dim streamWriter As StreamWriter = New StreamWriter(httpWebRequest.GetRequestStream()) 

    Dim json As String = "{""registration_ids"": [""" & regId & """], ""data"": {""message"": """ & MessageText & """}}" 

    Response.Write(json) 
    streamWriter.Write(json) 
    streamWriter.Flush() 
    streamWriter.Close() 

    Dim httpResponse As WebResponse = httpWebRequest.GetResponse() 
    Dim streamReader As StreamReader = New StreamReader(httpResponse.GetResponseStream()) 

    result = streamReader.ReadToEnd() 

    Response.Write(result) 

當我運行這個函數,它會得到一個成功的消息。所以一切似乎都正常,但我的設備沒有收到任何東西。我究竟做錯了什麼?謝謝

回答

-1

This?

push.addEventListener(PushNotificationEvent.COMING_FROM_NOTIFICATION_EVENT, onPushMessage); 
+5

請解釋。如果這是來自OP代碼的一行,您認爲這是問題的根源,請解釋原因。如果這是你提出的解決方案,請解釋它如何適應以及如何解決問題。事實上,這實際上更多的是[評論](http://stackoverflow.com/help/privileges/comment)而不是答案。 –