How to send push notification with the image using FCM, I have used below things but still just getting only title and text in the notification.
I have used cordova based hybrid application. If anyone has any idea, please let me know.
Sample curl code:
curl https://fcm.googleapis.com/fcm/send -X POST \
--header "Authorization: key=<AUT KEY>" \
--Header "Content-Type: application/json" \
-d '
{
"to": "<to TOKEN>"
"notification":{
"title":"New Notification!",
"body":"Test",
"color":"#ff0000",
"icon":"noti_icon",
"img_url": "https://static.pexels.com/photos/4825/red-love-romantic-flowers.jpg",
"image" : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
"avatar_url" : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
"url" : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
"image_url" : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
"largeIcon":"http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
},
"data" : {
"img_url": "https://static.pexels.com/photos/4825/red-love-romantic-flowers.jpg",
"image" : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
"avatar_url" : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
"url" : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
"image_url" : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
"message": "Firebase Push Message Using API",
"largeIcon":"http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
"main_picture":"http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
},
"priority":1
}'
Thanks.
Finally after 2 days suffer, I got solution to display all types of notification in cordova application.
Plugin Details: https://github.com/phonegap/phonegap-plugin-push
Make sure you have to remove cordova-plugin-firebase if you want to user above plugin, else it will conflict with each other.
For more detail please check above git link which have detail flow of this plugin. I have tested it on android#8.0.0
Related
I have added this to capacitor.config.json file
"PushNotifications": {
"presentationOptions": [
"badge", "sound", "alert"
]
}
but it not work please help me
I've been trying to configure push-proxy on my server.i have done complete installation from here
mattermost-push-proxy
After installation my server is running but when i want to test notification from curl
curl http://172.104.182.36:8066/api/v1/send_push -X POST -H "Content-Type: application/json" -d '{ "message":"test", "badge": 1, "platform":"android", "server_id":"c5brhfxaeb8o3qkcc3dfc47coy", "device_id":"android:el99uTDjv0A:APA91bGnVbuZl9W2lQSSokXYECVa4Tgt-wrnOxQFh4r51pzdDaFxbXUrJXQgmcSaPYToyIA5Dc9CCLPvYPNBF8bnrZdCjOSIaJmgB0Uhusj-8IoVCtFfAkF_l_PfRq0TMQf7L_RYMLqo"}'
I got this error:
{"error":"unknown transport error","status":"FAIL"}
please help me.
thanks
First ensure that your config file has the appropriate certificates and ApiKeys like:
{
"ListenAddress":":8066",
"ThrottlePerSec":300,
"ThrottleMemoryStoreSize":50000,
"ThrottleVaryByHeader":"X-Forwarded-For",
"EnableMetrics": false,
"ApplePushSettings": [
{
"Type" : "apple_rnbeta",
"ApplePushUseDevelopment": false,
"ApplePushCertPrivate": "./config/aps_rnbeta_production_priv.pem",
"ApplePushCertPassword": "",
"ApplePushTopic": "com.mattermost.rnbeta"
},
{
"Type" : "apple",
"ApplePushUseDevelopment": false,
"ApplePushCertPrivate": "./config/aps_rn_production_priv.pem",
"ApplePushCertPassword": "",
"ApplePushTopic": "com.mattermost.rn"
}
],
"AndroidPushSettings": [
{
"Type" : "android_rn",
"AndroidApiKey": "AIzaSyA1sl9LXXXxXXXxXXXxXXXxX_XXXXXX"
},
{
"Type" : "android",
"AndroidApiKey": "AIzaSyA1sl9LXXXxXXXyXXXxXXXyX_XXXXYY"
}
]
}
That being said just because you are using your own push-proxy server you need to build and compile the apps yourself so that the above certificates and Android ApiKeys match with your registered device tokens.
when building the app yourself don't forget to change the bundleId on iOS and packageId on Android so they also match with your certificates and keys.
I'm migrating my Android and iOS apps from parse.com to Parse Server (by the way I'm using a Parse test app but I guess it's not relevant to this issue). After the migration, everything is working well but the push notifications to Android device (they are working well to my iOS app).
This is what I've done so far.
1. In my Parse Server code (on Digital Ocean by the way), in /home/parse/index.js I've initialized Parse Server this way:
var api = new ParseServer({
databaseURI: databaseUri || '<my mongodb url>',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || '<my app ID>',
masterKey: process.env.MASTER_KEY || '<my master Key>',
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
push: {
android: {
senderId: '<my GCM sender Id>',
apiKey: '<my GCM API Key>'
},
ios: [{
pfx: '/home/parse/<my dev P12>',
passphrase: '',
cert: '',
key: '',
bundleId: '<my bundle ID>',
production: false
},
{
pfx: '/home/parse/<my prod P12>',
passphrase: '',
cert: '',
key: '',
bundleId: '<my bundle ID>',
production: true
}]
}
});
I’ve taken "my GCM sender ID" from my Google Developer Consoler, it’s the 12 digits number from Settings > Project number.
I’ve tried with 3 different "my GCM API Key", one without app restrictions, one available only for my android/debug.keystore and one available only for my app keystore.
I’ve checked that I have selected this app in my Google Developer console and that my package id is correct in all places.
2. Once I’ve made this change I’ve restarted Parse Server with
pm2 delete all // this with parse user
pm2 start ecosystem.json // this with parse user
pm2 save // this with parse user
sudo service nginx restart //this with my sudo user
3. In Android I’m initializing Parse this way:
public static void initParse(Application app) {
ctxt = app.getApplicationContext();
Parse.enableLocalDatastore(app);
// Old version
Parse.initialize(app, "<my app id>", "<my client key>");
// New version
//Parse.initialize(new Parse.Configuration.Builder(ctxt)
// .applicationId("<my app id>")
// .clientKey(null)
// .server("https://<my new server>/parse/")
// .build()
//);
ParseUser.enableRevocableSessionInBackground();
}
I’m not initializing with the new method because it’s crashing (this is the issue of another question Android switch from Parse to Parse Server crashes), but I guess this initialization doesn’t affect the push notifications.
4. In Android I’ve added this to my Android Manifest:
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:<my GCM sender Id>" />;
The rest of my manifest and my GCM configuration is the same I had before the migration.
5. And as a summary.
With old parse.com push notifications worked well with Android and iOS.
With new Parse Server and the code described above iOS push notifications are working well.
With new Parse Server and the code described above Android push notifications are not being received.
With my new Parse Dashboard installed in Digital Ocean when sending push notifications both to iOS and to Android Dashboard gives a Saved! what makes me thing it’s a problem with my Android app and not with my Parse Dashboard/Parse Server configuration.
What am I missing here?
Make sure that your Parse SDK libraries are updated!
I was having a bunch of trouble getting Android notifications pushed from Parse Dashboard too, but it was all resolved when I updated my libraries to Parse 1.13.0 and Bolts 1.4.0.
you can try using "CURL" to specified only "android" device.
curl -X POST \
-H "X-Parse-Application-Id: you_app_id" \
-H "X-Parse-Master-Key: your_master_key" \
-H "Content-Type: application/json" \
-d '{
"where": {
"deviceType": {
"$in": [
"android"
]
}
},
"data": {
"title": "The Shining",
"alert": "All work and no play makes Jack a dull boy."
}
}'\ http://your_server_address/parse/push
Then you can find out the exactly what is wrong.
I'm developing an Ionic (version 1.3.1) application and trying use Ionic push.
The application is correctly registering to ionic server but I still don't receive any notification in my device. The only error I get is the below notification status:
{
"notification": "808cde89-eb21-40d7-9999-b86e5f86f1d3",
"token": {
"type": "android",
"token": "dkYxYGcKeNo:APA91bE4OXhzkOUOSF1EsXxgY9Cd0Uu9-A98Ak5prdMIGUd10tLljacgKs7zAp1WPLF-bDiy3pkdroc9l8vWy4sXdfansr56-rIF59wJfR1e7EibJZHFO5DFxCThpT_ZgVn_T_0n8an1",
"id": "ea40d3bc7561cc4f0d28ac49ce87fd3a",
"app_id": "7ab91503",
"invalidated": null,
"created": "2016-09-17T11:31:53.481151+00:00",
"valid": true
},
"uuid": "0ebe9454-aebc-4c0b-b5b0-056920817f56",
"status": "error",
"error": "GCM_INVALID_AUTH",
"created": "2016-09-17T14:31:20.517783+00:00",
"user_id": null
}
I'm supposing ionic server is not sending the notification to device as the status is error, but I don't know the reason why I'm getting this GCM_INVALID_AUTH error. What could cause this problem?
You need migrate your project from GCM to FCM (firebase cloud message) , and use new server key.
SOLVED
I was using the wrong credentials from Google Cloud Platform. When I set to server key the problem was solved.
I'm using ngCordova cordovaPushV5 and when I open the app I get the registration id just fine, but when I send the notification via POST request using Postman I do not get a notification on the device.
Here is the curl request I'm trying:
curl -X POST -H "Authorization: Bearer MY_API_TOKEN" -H "Content-Type: application/json" -d '{
"tokens": ["dO-ocODiZSE:APA91bFTEvGakImDE3Jk-qhYyGwl86qq4R8bQuKikaQeyeYmDkaxWjMZTv47SmX0rvYUWLjpeG24LsQYIuE2KJA0I4U9Hq-2HyG9LuST3jn5SwLc1FTYQbyttIuKaGKHMDMTIaTdLyIx"],
"profile": "trader_mobile",
"notification": {
"message": "Test"
}
}' "https://api.ionic.io/push/notifications"
And this is the response I get:
{
"meta": {
"request_id": "5ac67cae-458e-4ff4-aa9a-ac86f4aff873",
"version": "2.0.0-beta.0",
"status": 201
},
"data": {
"app_id": "de12c106",
"status": "open",
"config": {
"profile": "trader_mobile",
"tokens": [
"dO-ocODiZSE:APA91bFTEvGakImDE3Jk-qhYyGwl86qq4R8bQuKikaQeyeYmDkaxWjMZTv47SmX0rvYUWLjpeG24LsQYIuE2KJA0I4U9Hq-2HyG9LuST3jn5SwLc1FTYQbyttIuKaGKHMDMTIaTdLyIx"
],
"notification": {
"message": "Test"
}
},
"uuid": "7efef50c-72bf-4e08-a176-4c28de8b2258",
"state": "enqueued",
"created": "2016-09-05T17:00:46.425695+00:00"
}
}
But I still do not receive the notification on the device.
I've set up my gcm api key in my security profile in my Ionic Dashbaord, and uploaded my app with ionic upload and did ionic io init. I've tried every solution I could find, and I've tried just about every command in different orders. As well as removing the platform and adding it again. Still nothing, what am I doing wrong?