I am trying for days now to get a basic application with push notification running.
I am using PhoneGap Build (Desktop App) and am testing on a Android Device. I tried various tutorials but they never seem to work. Running the following code just gives no reaction at all.
This is my current code:
config.xml I added the following lines:
<preference name="android-build-tool" value="gradle" />
<plugin name="phonegap-plugin-push" source="npm">
<param name="SENDER_ID" value="540732047871" />
</plugin>
index.html
<body>
<div class="app">
<h1>PhoneGap</h1>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
index.js
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
var push = PushNotification.init({
"android": {
"senderID": "540732047871"
},
"ios": {"alert": "true", "badge": "true", "sound": "true"},
"windows": {}
});
push.on('registration', function(data) {
console.log("registration event");
document.getElementById("regId").innerHTML = data.registrationId;
console.log(JSON.stringify(data));
});
push.on('notification', function(data) {
console.log("notification event");
console.log(JSON.stringify(data));
var cards = document.getElementById("cards");
var card = '<div class="row">' +
'<div class="col s12 m6">' +
' <div class="card darken-1">' +
' <div class="card-content black-text">' +
' <span class="card-title black-text">' + data.title + '</span>' +
' <p>' + data.message + '</p>' +
' </div>' +
' </div>' +
' </div>' +
'</div>';
cards.innerHTML += card;
push.finish(function () {
console.log('finish successfully called');
});
});
push.on('error', function(e) {
console.log("push error");
});
}};
Am I doing something wrong? I'm using code based on the "github"-page of the "phonegap-plugin-push". Any ideas what I seem to have missed in creating the project?