GCM push notification not working in Android Phonegap app

I work in HTML5 Phonegap android application GCM push notification

. But I tried several times but didn't get any results: - (

Please help me .. I have been trying to work since the last three days.

Am uses a Push plugin: com.phonegap.plugins.PushPlugin

** My Js code:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady()
{
    alert('deviceready');


// result contains any message sent from the plugin call
    var app = {
    successHandler: function(result) {
        alert('Callback Success! Result = '+result)
    },
    errorHandler:function(error) {
        alert(error);
    },
    onNotificationGCM: function(e) {
        alert('onNotificationGCM');
            switch( e.event )
            {
                case 'registered':
                    if ( e.regid.length > 0 )
                    {
                        console.log("Regid " + e.regid);
                        alert('registration id = '+e.regid);
                    }
                break;

                case 'message':
                  // this is the actual push notification. its format depends on the data model from the push server
                  alert('message = '+e.message+' msgcnt = '+e.msgcnt);
                break;

                case 'error':
                  alert('GCM error = '+e.msg);
                break;

                default:
                  alert('An unknown GCM event has occurred');
                  break;
            }
        }
    }
    setTimeout(function(){
        var pushNotification = window.plugins.pushNotification;
        pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"236728063055","ecb":"app.onNotificationGCM"});
    },2000);

}

      

** Manifest file

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.test.pushDummy" xmlns:android="http://schemas.android.com/apk/res/android">
    <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" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="CordovaApp" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:exported="true" android:name="com.plugin.gcm.PushHandlerActivity" />
        <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="com.test.pushDummy" />
            </intent-filter>
        </receiver>
        <service android:name="com.plugin.gcm.GCMIntentService" />
    </application>
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <permission android:name="com.test.pushDummy.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.test.pushDummy.permission.C2D_MESSAGE" />
</manifest>

      

+3


source to share


1 answer


Try moving the function var app

to an external device. It will work.



+2


source







All Articles