我正在使用带有 Push Plugin ( https://github.com/phonegap-build/PushPlugin ) 的最新 Cordova 版本。
我正在尝试在 Android Emulator 上使用 github 页面上的示例。我正在使用 Google API 运行 nexus 4 VD。已安装 Google 软件包,我已将正确的 senderID 放入代码中。
我的问题是:应用程序正确注册并获取其 regID,但没有收到任何通知。
为了发送通知,我尝试了 pushmeup(ruby gem)和这个:http ://gcm.codeplex.com 。
当然,我放置了正确的设备令牌以及正确的服务器 API 密钥。两个服务器应用程序都成功并且不给我任何错误。
这是我的安卓清单:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true"
android:versionCode="1" android:versionName="0.0.1"
android:windowSoftInputMode="adjustPan" package="io.cordova.hellocordova"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="18" />
<supports-screens android:anyDensity="true"
android:largeScreens="true" android:normalScreens="true"
android:resizeable="true" android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_TASKS" />
<permission android:name="io.cordova.hellocordova.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="io.cordova.hellocordova.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application android:allowBackup="true" android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:label="@string/app_name" android:name="HelloCordova"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.plugin.gcm.PushHandlerActivity" />
<service android:name="com.plugin.gcm.GCMIntentService" />
<receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="io.cordova.hellocordova" />
</intent-filter>
</receiver>
</application>
</manifest>
这是我的 config.xml :
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.helloCordova" version="2.0.0" xmlns="http://www.w3.org/ns/widgets">
<name>Hello Cordova</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<access origin="*" />
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<plugin name="Device" value="org.apache.cordova.Device" />
<plugin name="PushPlugin" value="com.plugin.gcm.PushPlugin" />
<plugin></plugin>
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<feature name="PushPlugin">
<param name="android-package" value="com.plugin.gcm.PushPlugin" />
</feature>
</widget>
所有代码都来自插件示例,我没有更改任何内容。我的包名是 io.cordova.hellocordova。
任何帮助将不胜感激。
编辑:看来这可能是防火墙问题。我正在等待网络团队为服务打开端口