cordova - Pushwoosh and Android Phonegap App not communicating -


the problem

okay have phonegap (2.3.0) android application pushwoosh manage push notifications. followed instructions, , got app few wording errors working. app seems run fine, doesn't seem pushwoosh pushing gcm (google cloud messanger), turn isn't pushing app. think wrong, first time using gcm , pushwoosh.

on pushwoosh console page shows each "push" completed no errors, on gcm console doesn't show requests, nor notification pop on phone.

i have gcm api key (server key) in xml , pushwoosh correct xxxxx-xxxxx key. here code better outline how code setup (and maybe can see i'm missing).


the code

here androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?> 

<supports-screens     android:largescreens="true"     android:normalscreens="true"     android:smallscreens="true"     android:resizeable="true"     android:anydensity="true"     />   <uses-sdk android:minsdkversion="8" android:targetsdkversion="17"/>  <uses-permission android:name="android.permission.camera" /> <uses-permission android:name="android.permission.vibrate" /> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location" /> <uses-permission android:name="android.permission.access_location_extra_commands" /> <uses-permission android:name="android.permission.receive_sms" /> <uses-permission android:name="android.permission.record_audio" /> <uses-permission android:name="android.permission.record_video"/> <uses-permission android:name="android.permission.modify_audio_settings" /> <uses-permission android:name="android.permission.read_contacts" /> <uses-permission android:name="android.permission.write_contacts" />    <uses-permission android:name="android.permission.write_external_storage" />    <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.broadcast_sticky" /> <uses-permission android:name="android.permission.access_network_state"/>  <!--library--> <uses-permission android:name="android.permission.read_phone_state"/>  <!-- gcm connects google services. --> <uses-permission android:name="android.permission.internet"/>  <!-- gcm requires google account. --> <uses-permission android:name="android.permission.get_accounts"/>  <!-- keeps processor sleeping when message received. --> <uses-permission android:name="android.permission.wake_lock"/>   <!-- creates custom permission app can receive messages.  note: permission *must* called package.permission.c2d_message,     package application's package name. --> <permission      android:name="com.springmobile.employee.permission.c2d_message"      android:protectionlevel="signature"/> <uses-permission      android:name="com.springmobile.employee.permission.c2d_message"/>  <!-- app has permission register , receive data message. --> <uses-permission      android:name="com.google.android.c2dm.permission.receive"/>    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:allowbackup="true">    <!-- service sending location updates --> <service android:name="com.arellomobile.android.push.geolocationservice"/> <intent-filter>      <action android:name="com.springmobile.employee.message"/>      <category android:name="android.intent.category.default"/>  </intent-filter>  <intent-filter>      <action android:name="android.intent.action.main"/>      <category android:name="android.intent.category.launcher"/>  </intent-filter>     <activity android:name="com.arellomobile.android.push.pushwebview"/>      <activity android:name="com.arellomobile.android.push.messageactivity"/>      <activity android:name="com.arellomobile.android.push.pushhandleractivity"/>      <!--     broadcastreceiver receive intents gcm     services , handle them custom intentservice.      com.google.android.c2dm.permission.send permission necessary     gcm services can send data messages app.     -->     <receiver     android:name="com.google.android.gcm.gcmbroadcastreceiver"     android:permission="com.google.android.c2dm.permission.send">     <intent-filter>     <!-- receives actual messages. -->     <action android:name="com.google.android.c2dm.intent.receive"/>     <!-- receives registration id. -->     <action android:name="com.google.android.c2dm.intent.registration"/>     <category android:name="com.springmobile.employee"/>     </intent-filter>     </receiver>      <!--     application-specific subclass of pushgcmintentservice     handle received messages.     -->     <service android:name="com.arellomobile.android.push.pushgcmintentservice"/>     <activity android:name="org.apache.cordova.example.cordovaexample" android:label="@string/app_name"             android:theme="@android:style/theme.black.notitlebar"             android:configchanges="orientation|keyboardhidden">         <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> </application> 


here phonegap plugin config.xml

<plugins> <plugin name="pushnotification" value="com.pushwoosh.plugin.pushnotifications.pushnotifications" onload="true"/> </plugins> 

here js phonegap page initialize , listen pushwoosh notification.

function initpushwoosh() { var pushnotification = window.plugins.pushnotification; pushnotification.ondeviceready();  pushnotification.registerdevice({ projectid: "i_have_my_project_id_here", appid : "this_is_my_pushwoosh_id" },     function(status) {         var pushtoken = status;         console.warn('push token: ' + pushtoken);     },     function(status) {         console.warn(json.stringify(['failed register ', status]));     } );  document.addeventlistener('push-notification', function(event) {     var title = event.notification.title;         var userdata = event.notification.userdata;          if(typeof(userdata) != "undefined") {         console.warn('user data: ' + json.stringify(userdata));     }      navigator.notification.alert(title); }); }  function init() { document.addeventlistener("deviceready", initpushwoosh, true);  //rest of code document.addeventlistener('push-notification', function(event) {     var title = event.notification.title;         var userdata = event.notification.userdata;      console.warn('user data: ' + json.stringify(userdata));     navigator.notification.alert(title); }); }  function initpushwoosh() { var pushnotification = window.plugins.pushnotification; pushnotification.ondeviceready();  document.addeventlistener('push-notification', function(event) {                             var title = event.notification.title;                             var userdata = event.notification.userdata;                              if(typeof(userdata) != "undefined") {                                 console.warn('user data: ' + json.stringify(userdata));                             }                              navigator.notification.alert(title);                              pushnotification.stopgeopushes();                           }); }  function registerpushwoosh() { var pushnotification = window.plugins.pushnotification; //projectid: "google_project_id", appid : "pushwoosh_app_id" pushnotification.registerdevice({ projectid: "1039894503284", appid : "ee861-b95a3" },                                 function(token) {                                     alert(token);                                     onpushwooshinitialized(token);                                 },                                 function(status) {                                     alert("failed register: " +  status);                                     console.warn(json.stringify(['failed register ', status]));                                 }); }  function unregisterpushwoosh() { var pushnotification = window.plugins.pushnotification; pushnotification.unregisterdevice(function(token) {                                     alert("unregistered, old token " + token);                                 },                                 function(status) {                                     alert("failed unregister: " +  status);                                     console.warn(json.stringify(['failed unregister ', status]));                                 }); }  //set settings pushwoosh or set tags, must called after successful registration function onpushwooshinitialized(pushtoken) { //output token console console.warn('push token: ' + pushtoken);  var pushnotification = window.plugins.pushnotification;  //set multi notificaiton mode //pushnotification.setmultinotificationmode();  //set single notification mode //pushnotification.setsinglenotificationmode();  //disable sound , vibration //pushnotification.setsoundtype(1); //pushnotification.setvibratetype(1);  pushnotification.setlightscreenonnotification(false);  //goal count //pushnotification.sendgoalachieved({goal:'purchase', count:3});  //goal no count //pushnotification.sendgoalachieved({goal:'registration'});  //setting list tags //pushnotification.settags({"mytag":["hello", "world"]});  //settings tags pushnotification.settags({devicename:"hello", deviceid:10},                                 function(status) {                                     console.warn('settags success');                                 },                                 function(status) {                                     console.warn('settags failed');                                 });  function geolocationsuccess(position) {     pushnotification.sendlocation({lat:position.coords.latitude, lon:position.coords.longitude},                              function(status) {                                   console.warn('sendlocation success');                              },                              function(status) {                                   console.warn('sendlocation failed');                              }); };  // onerror callback receives positionerror object // function geolocationerror(error) {     alert('code: '    + error.code    + '\n' +           'message: ' + error.message + '\n'); }  function getcurrentposition() {     navigator.geolocation.getcurrentposition(geolocationsuccess, geolocationerror); }  //greedy method user position every 3 second. works demo. //  setinterval(getcurrentposition, 3000);  //this method gives position once //  navigator.geolocation.getcurrentposition(geolocationsuccess, geolocationerror);  //this method should track user position per phonegap docs. //  navigator.geolocation.watchposition(geolocationsuccess, geolocationerror, { maximumage: 3000, enablehighaccuracy: true });  //pushwoosh android specific method cares battery pushnotification.startgeopushes(); }  var app = { // application constructor initialize: function() {     this.bindevents(); }, // bind event listeners // // bind events required on startup. common events are: // 'load', 'deviceready', 'offline', , 'online'. bindevents: function() {     document.addeventlistener('deviceready', this.ondeviceready, false); }, // deviceready event handler // // scope of 'this' event. in order call 'receivedevent' // function, must explicity call 'app.receivedevent(...);' ondeviceready: function() {     initpushwoosh();     app.receivedevent('deviceready');      //optional: create local notification alert     //var pushnotification = window.plugins.pushnotification; //pushnotification.clearlocalnotification(); //pushnotification.createlocalnotification({"msg":"message", "seconds":30, "userdata":"optional"});  }, // update dom on received event receivedevent: function(id) {     var parentelement = document.getelementbyid(id);     var listeningelement = parentelement.queryselector('.listening');     var receivedelement = parentelement.queryselector('.received');      listeningelement.setattribute('style', 'display:none;');     receivedelement.setattribute('style', 'display:block;');      console.log('received event: ' + id); } }; 

here pushwoosh.js code

(function(cordova) {  function pushnotification() {}  // call register push notifications , retreive devicetoken pushnotification.prototype.registerdevice = function(config, success, fail) {     cordova.exec(success, fail, "pushnotification", "registerdevice", config ? [config] : []); };  // call set tags device pushnotification.prototype.settags = function(config, success, fail) {     cordova.exec(success, fail, "pushnotification", "settags", config ? [config] : []); };  // call send geo location device pushnotification.prototype.sendlocation = function(config, success, fail) {     cordova.exec(success, fail, "pushnotification", "sendlocation", config ? [config] : []); };  //android only---- pushnotification.prototype.unregisterdevice = function(success, fail) {     cordova.exec(success, fail, "pushnotification", "unregisterdevice", []); };  //config params: {msg:"message", seconds:30, userdata:"optional"} pushnotification.prototype.createlocalnotification = function(config, success, fail) {     cordova.exec(success, fail, "pushnotification", "createlocalnotification", config ? [config] : []); };  pushnotification.prototype.clearlocalnotification = function() {     cordova.exec(null, null, "pushnotification", "clearlocalnotification", []); };  //advanced background task track device position , not drain battery pushnotification.prototype.startgeopushes = function(success, fail) {     cordova.exec(success, fail, "pushnotification", "startgeopushes", []); };  pushnotification.prototype.stopgeopushes = function(success, fail) {     cordova.exec(success, fail, "pushnotification", "stopgeopushes", []); };  //sets multi notification mode on pushnotification.prototype.setmultinotificationmode = function(success, fail) {     cordova.exec(success, fail, "pushnotification", "setmultinotificationmode", []); };  //sets single notification mode pushnotification.prototype.setsinglenotificationmode = function(success, fail) {     cordova.exec(success, fail, "pushnotification", "setsinglenotificationmode", []); };  //type: 0 default, 1 no sound, 2 pushnotification.prototype.setsoundtype = function(type, success, fail) {     cordova.exec(success, fail, "pushnotification", "setsoundtype", [type]); };    //type: 0 default, 1 no vibration, 2 pushnotification.prototype.setvibratetype = function(type, success, fail) {     cordova.exec(success, fail, "pushnotification", "setvibratetype", [type]); };    pushnotification.prototype.setlightscreenonnotification = function(on, success, fail) {     cordova.exec(success, fail, "pushnotification", "setlightscreenonnotification", [on]); };  //set enable led blinking when notification arrives , display off pushnotification.prototype.setenableled = function(on, success, fail) {     cordova.exec(success, fail, "pushnotification", "setenableled", [on]); };  //{goal:'name', count:3} (count optional) pushnotification.prototype.sendgoalachieved = function(config, success, fail) {     cordova.exec(success, fail, "pushnotification", "sendgoalachieved", config ? [config] : []); };  //android end----  //ios only---- pushnotification.prototype.ondeviceready = function() {     cordova.exec(null, null, "pushnotification", "ondeviceready", []); };  // call detailed status of remotenotifications pushnotification.prototype.getremotenotificationstatus = function(callback) {     cordova.exec(callback, callback, "pushnotification", "getremotenotificationstatus", []); };  // call set application icon badge pushnotification.prototype.setapplicationiconbadgenumber = function(badge, callback) {     cordova.exec(callback, callback, "pushnotification", "setapplicationiconbadgenumber", [{badge: badge}]); };  // call clear notifications notification center pushnotification.prototype.cancelalllocalnotifications = function(callback) {     cordova.exec(callback, callback, "pushnotification", "cancelalllocalnotifications", []); }; //ios end----  // event spawned when notification received while application active pushnotification.prototype.notificationcallback = function(notification) {     var ev = document.createevent('htmlevents');     ev.notification = notification;     ev.initevent('push-notification', true, true, arguments);     document.dispatchevent(ev); };  cordova.addconstructor(function() {     if(!window.plugins) window.plugins = {};     window.plugins.pushnotification = new pushnotification(); });  })(window.cordova || window.cordova || window.phonegap); 

screenshots of gcm, pushwoosh , eclipse

sorry lengthy want make sure have here. not enough rep post images links below.

gcm api server key, pushwoosh control panel, , eclipse setup


thanks!

lets check configuration , setup proper push woosh notification .other push notification service work in phone-gap can check out.you can find phone gap code(zip),proper documentation configuration , setup , how use api using java script


Comments

Popular posts from this blog

asp.net mvc 3 - Using mvc3, I need to add a username/password to the sql connection string at runtime -

kineticjs - draw multiple lines and delete individual line -

thumbnails - jQuery image rotate on hover -