推送通知未在Cordova Android App中接收

时间:2016-11-30 08:49:27

标签: android cordova push-notification google-cloud-messaging pushwoosh

我没有在Cordova Android App上收到推送通知。使用相同的代码,我可以在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 Panel发送时,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>

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

您可能需要尝试Apache Cordova / Phonegap Push Notification Tutorial中列举的以下内容:

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

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

答案 1 :(得分:0)

使用Pushbot插件进行cordova应用程序推送通知