In order to get started with Android you will have to obtain a projectNumber and a server apiKey
As of September 2016 it's not possible to obtain a new GCM server key. Instead, use an FCM server key.
To create a Google API project:
- Open the Firebase Developers Console (https://console.firebase.google.com).
- If you haven't created an API project yet, click Create Project.
- Supply a project name and click Create.
- Once the project has been created, the Firebase Overview page is displayed. In the top left you'll see the name of your project and a cog. Click the cog and select Project Settings.
- Click the Settings->Cloud Messaging tab.
- Write down your Sender ID (it should be all digits) and your Server key (has upper and lower case letters, numbers, underscores and dashes)
In this example, my sender ID is 111111111111 and my server key is abc-123
Use the Push.Configure
function on client and server.
On the client
Push.Configure({
android: {
senderID: 111111111111,
alert: true,
badge: true,
sound: true,
vibrate: true,
clearNotifications: true
// icon: '',
// iconColor: ''
},
ios: {
alert: true,
badge: true,
sound: true
}
});
Additionally you have to touch mobile-config.js
App.configurePlugin('phonegap-plugin-push', {
SENDER_ID: 111111111111
});
This is due to changes in the cordova plugin it self
Server:
Push.Configure({
apn: {
certData: Assets.getText('apnDevCert.pem'),
keyData: Assets.getText('apnDevKey.pem'),
passphrase: 'xxxxxxxxx',
production: true,
//gateway: 'gateway.push.apple.com',
},
gcm: {
apiKey: 'abc-123',
projectNumber: 111111111111
}
// production: true,
// 'sound' true,
// 'badge' true,
// 'alert' true,
// 'vibrate' true,
// 'sendInterval': 15000, Configurable interval between sending
// 'sendBatchSize': 1, Configurable number of notifications to send per batch
// 'keepNotifications': false,
//
});
* The server config differs from the README config in that it includes the projectNumber.
* The project number does not require any type of quotes.
* The apiKey requires quotes.
To link your FCM service with your app in the Play Store.
- Go to the Google Play Developer Console (https://play.google.com/apps/publish)
- Select your app
- In the left column, click Services & APIs
- Find Firebase Cloud Messaging (FCM) and click the Link Sender ID button
- Enter your FCM sender ID and click Link
For more info and checking the validity of a server key, reference official documentation
To show you app's icon in the notification you will have to prepare an image file with your icon in it and every else being transparent. You can see here how it can be done.
Then put the file (e.g. "logo.png") in your project directory under this path:
cordova-build-override/platforms/android/res/drawable/
In your Push.configure
block on the client you have to set the name of the file and you can also define a color:
Push.Configure({
android: {
...
icon: 'logo',
iconColor: '#4cae4c',
},