android - Cordova PushPlugin 在 Android 模拟器上未收到通知

标签 android cordova push-notification emulation google-cloud-messaging

我正在使用最新的 Cordova 版本和 Push 插件 ( https://github.com/phonegap-build/PushPlugin )。

我正在尝试在 Android 模拟器上使用 github 页面上的示例。 我正在使用 Google API 运行 Nexus 4 VD。 Google 软件包已安装,我已将正确的发件人 ID 放入代码中。

我的问题是:应用程序正确注册并获取其 regID,但没有收到任何通知。

为了发送通知,我尝试了pushmeup(ruby gem),这个:http://gcm.codeplex.com

当然,我输入了正确的设备 token 以及正确的服务器 API key 。 两个服务器应用程序都成功并且没有给我任何错误。

这是我的 Android list :

<?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="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcd8d9cafcdfd3ced8d3cadd92ddccdddfd4d992d3cedb" rel="noreferrer noopener nofollow">[email protected]</a>" 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。

任何帮助将不胜感激。

编辑:看起来可能是防火墙问题。我正在等待网络团队为该服务打开端口

最佳答案

除非您安装一些额外的库,否则推送插件无法在模拟器中运行。

查看标题为“安装帮助程序库并设置模拟器”的部分:

http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

关于android - Cordova PushPlugin 在 Android 模拟器上未收到通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18783250/

相关文章:

java - 查找运行 web 服务的 android 设备的 IP 地址

iphone - 我在哪里可以下载 StoreKit.framework

swift - 有没有办法在新通知到达时删除已发送的通知?

android - Firebase 云消息传递 Java 客户端

android - 处理 ACTION_MANAGE_WRITE_SETTINGS Activity 的正确方法

java.security.cert.CertPathValidatorException : Trust anchor for certification path not found

cordova - Cordova 3.4.0 上的文件系统失败 "Could not create target file"

ios - 应用程序未运行时不会收到远程通知

android - 将 Firebase DB 与本地数据库一起使用

javascript - Ionic 没有创建 cordova.js