0

I am using phonegap push plugin

My problem is I got onNotification function alert message "Result :Ok" in real device also I checked.

My config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.xxxxxxxxxxx.xxxxxxxxxxxx" version="6.2" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>xxxxxxxx</name>
    <description>
       The #1 Mobile App to Earn Money on xxxxxx .
    </description>
    <author email="xxxxxx" href="http://xxxxxx.com">
        xxxxxx Team
    </author>
    <icon src="icon.png" />
    <content src="index.html" />
    <access origin="*" />
    <feature name="PushPlugin">
    <param name="android-package" value="com.plugin.gcm.PushPlugin" />
   </feature>
   <feature name="NetworkStatus">
    <param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
    </feature>
    <gap:plugin name="org.apache.cordova.InAppBrowser" />
    <icon src="icon.png" />
    <icon gap:platform="android" height="114" src="res/icon/android/icon-xxhdpi.png" width="114" />
    <icon gap:platform="android" height="96" src="res/icon/android/icon-xhdpi.png" width="96" />
    <icon gap:platform="android" height="72" src="res/icon/android/icon-hdpi.png" width="72" />
    <icon gap:platform="android" height="48" src="res/icon/android/icon-mdpi.png" width="48" />
    <icon gap:platform="android" height="36" src="res/icon/android/icon-ldpi.png" width="36" />
    <icon gap:platform="ios" src="res/icon/ios/icon.png" />
    <engine name="android" spec="^4.0.0" />
</widget>

And also added Internet permission in manifest.xml file.

My gcm code:

window.plugins.pushNotification.register(successHandler, errorHandler, {
    ecb      : 'onNotificationGCM',
    senderID : 'xxxxxxxxxxxxxx'// Google Project ID.
});

// Method to handle device registration for Android.
var onNotificationGCM = function(e) {
    alert(e.event);
    if('registered' === e.event) {
        // Successfully registered device.
        alert(e.regid);
    }
    else if('error' === e.event) {
        // Failed to register device.
        alert(e.msg);
    }
    else if('message' === e.event) {
        //mesage recived 
        alert(e.payload.message);
    }

};

// result contains any message sent from the plugin call
function successHandler (result) {
    alert('result = ' + result);
}

// result contains any error description text returned from the plugin call
function errorHandler (error) {
    alert('error = ' + error);
}

How to get registration id from gcm.

Braiam
  • 1
  • 11
  • 47
  • 78
nmkkannan
  • 1,261
  • 4
  • 27
  • 49

2 Answers2

0

Here is good example of notification using GCM for phonegap and it works fine Link is here

Orgil
  • 691
  • 7
  • 16
  • Problem in java to javascript call.In CordovaWebView sendJavascript method is deprecated.So any other way is available for call javascript from java. – nmkkannan May 04 '15 at 04:39
0
  1. Try the automatic install.
  2. Ensure that your project ID is correct
  3. Double check your deviceready event is defined properly and fired.

NOTE: If you get an OK response, it means the plugin is working without any errors. The reason you are not getting a registration ID could be something superficial.

Ajoy
  • 1,838
  • 3
  • 30
  • 57