推送通知未在Cordova Android应用中接收



我没有在Cordova Android应用程序上收到推送通知。使用相同的代码,我可以在iOS应用中收到推送通知。之前,我正在使用PhoneGap Build(PGB)的PushWoosh插件:

< gap:plugin name="com.pushwoosh.plugins.pushwoosh" version="3.4.2" />

收到了iOS和Android的推送通知,没有任何错误。

我最近更改了插件,并添加了一个新插件:

< gap:plugin name="pushwoosh-cordova-plugin" version="6.4.0" source="npm" />     

该设备在PushWoosh中注册并获取设备令牌。
GCM(php-backend)用于发送Android的推送通知。
在发送推送通知时,我正在从GCM获得成功的回应:

{"multicast_id":86307627949689xxxxx,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1480488792901983%a4d1b626f9xxxxxx"}]}

在任何情况下,无论是在运行背景还是前景还是封闭的情况下,Android应用程序都不会收到推送通知。

仍然从PushWoosh面板发送时,该应用程序的iOS和Android版本都在接收推送通知

参考文档:http://docs.pushwoosh.com/docs/cordova-phonegap

我的代码:

document.addEventListener("deviceready", DeviceReady, false);
function DeviceReady()
{
  window.pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");
  // should be called before pushwoosh.onDeviceReady
  document.addEventListener('push-notification', function(event) {
     navigator.notification.alert(JSON.stringify(event.notification));  
     //get the notification payload
     if (device.platform == 'android' || device.platform == 'Android') {    
             navigator.notification.alert(event.notification.message);          
    }else{
        navigator.notification.alert(event.notification.aps.alert);             
    }
     if (device.platform == 'iOS') {
        pushwoosh.setApplicationIconBadgeNumber(0);
     }
  });
  // Initialize Pushwoosh. This will trigger all pending push notifications on start.
  // projectid : GOOGLE_PROJECT_NUMBER
  pushwoosh.onDeviceReady({
    appid: "3FXXX-3CXXX",
    projectid: "4631220XXXXX"
  });
  pushwoosh.registerDevice(
    function(status) {
        var pushToken = status.pushToken;
        document.getElementById('hiddentoken').value = pushToken;               
    },function(status) {
        //~ alert("Error Status" + status );
 }); 
  //reset badges on app start
  pushwoosh.setApplicationIconBadgeNumber(0);
}

清单:

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:amazon="http://schemas.amazon.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:windowSoftInputMode="adjustPan" package="com.XXXXX.XXXXX" platformBuildVersionCode="22" platformBuildVersionName="5.1.1-1819727">
    <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.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <permission android:name="com.XXXXX.XXXXX.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
    <uses-permission android:name="com.XXXXX.XXXXX.permission.C2D_MESSAGE"/>
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
    <uses-permission android:name="com.sec.android.provider.badge.permission.READ"/>
    <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/>
    <uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS"/>
    <uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT"/>
    <uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE"/>
    <uses-permission android:name="com.sonymobile.home.permission.PROVIDER_INSERT_BADGE"/>
    <uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT"/>
    <uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE"/>
    <uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE"/>
    <uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS"/>
    <uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS"/>
    <uses-permission android:name="android.permission.READ_APP_BADGE"/>
    <uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS"/>
    <uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS"/>
    <permission android:name="com.XXXXX.XXXXX.permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature"/>
    <uses-permission android:name="com.XXXXX.XXXXX.permission.RECEIVE_ADM_MESSAGE"/>
    <uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE"/>
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:configChanges="locale|keyboard|keyboardHidden|orientation|screenSize" android:label="@string/app_name" android:name="com.XXXXX.XXXXX.Apppp" android:screenOrientation="portrait" android:windowSoftInputMode="adjustUnspecified|stateUnspecified">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
        <meta-data android:name="PW_LOG_LEVEL" android:value="DEBUG"/>
        <meta-data android:name="PW_NO_BROADCAST_PUSH" android:value="false"/>
        <receiver android:exported="true" android:name="com.google.android.gms.gcm.GcmReceiver" android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                <category android:name="com.XXXXX.XXXXX"/>
            </intent-filter>
        </receiver>
        <activity android:exported="false" android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
        <receiver android:name="com.pushwoosh.MessageAlertReceiver" android:permission="com.amazon.device.messaging.permission.SEND">
            <intent-filter>
                <action android:name="com.amazon.device.messaging.intent.REGISTRATION"/>
                <action android:name="com.amazon.device.messaging.intent.RECEIVE"/>
                <category android:name="com.XXXXX.XXXXX"/>
            </intent-filter>
        </receiver>
        <service android:name="com.pushwoosh.PushAmazonIntentService"/>
        <amazon:enable-feature android:name="com.amazon.device.messaging" android:required="false"/>
        <activity android:name="com.pushwoosh.richpages.RichPageActivity"/>
        <activity android:name="com.pushwoosh.MessageActivity"/>
        <activity android:name="com.pushwoosh.PushHandlerActivity"/>
        <activity android:name="com.pushwoosh.inapp.WebActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
        <service android:name="com.pushwoosh.inapp.InAppRetrieverService"/>
        <receiver android:enabled="true" android:name="com.pushwoosh.local.BootReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </receiver>
        <service android:exported="false" android:name="com.pushwoosh.GCMListenerService">
            <intent-filter android:priority="-50">
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            </intent-filter>
        </service>
        <service android:exported="false" android:name="com.pushwoosh.GCMInstanceIDListenerService">
            <intent-filter android:priority="-50">
                <action android:name="com.google.android.gms.iid.InstanceID"/>
            </intent-filter>
        </service>
        <service android:exported="false" android:name="com.pushwoosh.GCMRegistrationService"/>
        <service android:name="com.pushwoosh.location.GeoLocationService"/>
        <activity android:name="com.pushwoosh.internal.utils.PermissionActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
        <receiver android:name="com.pushwoosh.local.AlarmReceiver"/>
        <service android:enabled="true" android:exported="true" android:isolatedProcess="false" android:label="iBeacon" android:name="com.pushwoosh.thirdparty.radiusnetworks.ibeacon.service.IBeaconService"/>
        <service android:enabled="true" android:name="com.pushwoosh.thirdparty.radiusnetworks.ibeacon.IBeaconIntentProcessor"/>
        <service android:name="com.pushwoosh.beacon.PushBeaconService"/>
        <service android:enabled="true" android:exported="false" android:name="com.pushwoosh.internal.utils.LockScreenService"/>
    </application>
</manifest>

任何帮助将不胜感激。

使用PushBot插件进行Cordova应用程序push Notification

您可能想尝试以下内容,如Apache Cordova/Phonegap Push Notification教程:

  • 检查您是否已安装了推送通知插件
  • 确保您已经在SDK Manager中安装了所需的工具
  • 检查您已随附项目的cordova.js文件
  • 检查您在GCM Projects中创建的发件人ID
  • 确保您有互联网连接

您还可以从以下参考文献中获取有关Cordova应用程序中推送通知的更多提示和信息:

  • 如何在Cordova Android应用中制作GCM推送通知
  • 推送通知

清单文件只有一个接收器,由Pusperwoosh SDK提供,如果通知有效负载以其预期的格式,则该接收器只能显示推送通知。如果您需要显示从您自己的服务器发送的通知,则需要拥有自己的接收器,该接收器应该了解您发送的有效负载然后显示。

注意:最新的Play Services版本不支持多个GCMListenerServices。理想情况下,您应该拥有自己的一项服务,以了解推动是从服务器还是从Pushwoosh进行的,并相应地处理。在测试过程中,您可能会看到将推送有效载荷交付到多个GCMListenerServices的实例,但是此行为不一致,因此最好只拥有一项服务

相关内容

  • 没有找到相关文章

最新更新