我使用Freshplanet ANE为推送通知创建了一个Flash CS6 AIR for Android应用程序。一切似乎都有效,但我仍然没有在我的设备上收到通知。
以下是我的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)
当我运行此功能时,它会收到成功消息。所以一切似乎都正常,但我的设备没有收到任何东西。我究竟做错了什么?感谢
答案 0 :(得分:0)
Fresh Planet有许多分支,尝试这是最近的:
https://github.com/freshplanet/ANE-Push-Notification/tree/feature/famepop-withOptions
您需要更改JASON以发送这些值:
contentTitle <---- this is the title
contentText <---- this is the message
tickerText <---- this is showed in the task bar
答案 1 :(得分:-1)
此?
push.addEventListener(PushNotificationEvent.COMING_FROM_NOTIFICATION_EVENT, onPushMessage);