I have created a new Ionic app and setup the cordova local notifications plugin to have notifications run in the background without the need for an external server such as Google Cloud Messaging using this plugin.
https://github.com/katzer/cordova-plugin-local-notifications
Everything seems to work but for some reason the icon shown in the notification isn't the one that I am setting in the js below - can anyone suggest what is wrong - it does show an icon, (an alarm bell) but it isn't the one that have I specified.
// within my $ionicPlatform.ready
$scope.scheduleSingleNotification = function () {
$cordovaLocalNotification.schedule({
id: 1,
title: 'Warning',
text: 'My first local notification this will stick!',
icon: '../img/github-icon.png'
}).then(function (result) {
console.log('Notification #1 triggered');
});
};
I had same problem few months back but than i have given a hit and trial an it worked for
create the icons of all sizes and copy them to /platforms/android/res/
and respective folders of sizes i hope that will solve problem
An always give the path of img respect to your index file not the file in which your are coding but to the main file in which it's included
Make sure that the icon has a white or transparent background. If you take a look at the documentation:
Android notifications
icons should only be a white-on-transparent background image.
Related
I'm learning Notifications, I use Android Studio 4.0 with latest androidx.core.app.NotificationManagerCompat.
There is a sample code about Notifications in the project user-interface-samples.
I find there are many differents about Notifications between this androidx and previous API.
Must the Notifications style be the one of BigTextStyleNotification, BigPictureStyleNotification, InboxStyleNotification and MessagingStyleNotification ?
Following are the notification styles available :
Notification.BigPictureStyle, Notification.BigTextStyle,
Notification.DecoratedCustomViewStyle, Notification.InboxStyle,
Notification.MediaStyle, Notification.MessagingStyle
You can get more info on this link.
Just for information purposes, to create a notification without hustle and get all predefined formatting in one place, just do the following :
Go to the Project Tab of android studio and right click.
Click on New -> UI Component -> Notification
Enter the required notification name
To call this notification just enter the following :
<NotificationClassName>.createNotification(getApplicationContext());
I want my FCM notifications to include a custom image and a vibration pattern.
The AndroidNotification class that Firebase provides as an example has both of these variables, but I haven't seen any way to get it working.
I've tried adding both of these variables to my notification message through a c# class AndroidNotification which gets serialized to json.
This is the documentation that makes me think it should be possible
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
I have watched multiple online videos and went through multiple forms, but have still been unable to set a custom vibration pattern or display image along with my app icon.
Lots of places suggest that I use a data only message so I can handle displaying the notification myself, but if that is the only way to do it way does the AndroidNotification documentation(linked above) show fields for both vibrate_timings and image?
Note :
I've been testing on Android Versions 4, 5, and 8. On 8 I set up a notification channel and everything works fine with that including the vibrations, but still no image.
The image is included locally in the my apk at the same path as my custom icon.
Also my apk is built with unity but I don't think that should effect things.
Here is the json payload I'm sending, I get my custom sound, custom icon, custom color etc just fine, it's only the image and vibrate_timings that don't seem to be working.
{
"validate_only":false,
"message":{
"data":null,
"android":{
"collapse_key":"new_messages",
"priority":1,
"restricted_package_name":"",
"data":{
},
"notification":{
"title":"A spoon is ready!",
"body":"Grab it before someone else!",
"icon":"spoonsbuzz",
"channel_id":"cow",
"color":"#0000FF",
"sound":"cow.wav",
"vibrate_timings":[
"0.0s",
"0.2s",
"0.1s",
"0.2s",
"0.1s",
"1.5s"
],
"visibility":2,
"tag":"new_messages",
"click_action":"",
"body_loc_key":"",
"body_loc_args":[
],
"title_loc_key":"",
"title_loc_args":[
],
"image":"spoonsbuzzimage",
"notification_priority":4
}
},
"apns":null,
"token":"Bot"
}
}
I expected my devices to get a notification with the image I added to the payload as well as vibrate in the pattern I set using vibrate_timings. The notification does come in just fine and everything else works but neither the image or the custom vibrations are included.
It's been a long time, but if someone has this problem they should add the default_vibrate_timings field, like this:
{...
default_vibrate_timings: false,
vibrate_timings: [
"0.0s",
"0.2s",
"0.1s",
"o.2s"
],
...}
For reference: Documenation Link
I've been trying out the example in the doc (https://googlechrome.github.io/samples/app-install-banner/basic-banner/index.html) but don't seem to be able to trigger the "add to homepage" banner.
Is there a way of defining and manually triggering it? or building a popup to perform a similar action?
In the perfect world, i'd want the same popup to work for both ios and android.
Requirements has changed to display the "Add to homepage" banner.
You need to have:
a name and a short_name
an image sized 192x192
a service worker to make some stuff offline
You need to define an empty service worker like this:
self.addEventListener('install', function(event) {
});
self.addEventListener('fetch', function(event) {
});
in ionic push notifications, we can add "icon":"xxxxx" in "android" array to change a new (small) icon path ,
var push = new Ionic.Push({
"debug": true,
"pluginConfig": {
"android": {
"iconColor": "#343434",
"icon": "abc"
}
}
});
where the abc.png is from platform/android/res/drawable folder.
but is there any methods to change the push's large icon? Since, the iconColor is valid but I test lots of times , I cant change the color background to a large image.
anyone can help me.. Thanks!!
You can add an image property to the android object which is a string describing either a reference to an image in the drawables folder, an asset URI, or a remote URL. Although Ionic Push doesn't list itself as supporting this property, actual testing verifies it.
More information: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#images
Currently there is no support for the large icon through the FCM notification message payload.
See https://github.com/firebase/quickstart-android/issues/84 . The problem is known but the issue is closed.
I'm using ionic to build an android app. I'm using
$cordovaLocalNotification for local notifications. The notification works but it shows a default bell icon. How can I customize the notification icon?
$scope.scheduleSingleNotification = function () {
$cordovaLocalNotification.schedule({
id: 1,
title: 'GRM APP Builder',
text: 'Quer café?!?',
badge: 1,
icon: 'res://coffee.png',
data: {
customProperty: 'custom value 1'
}
}).then(function (result) {
console.log('Notification 1 triggered');
});
};
After spend hours with this question, I saw that one comment above it's really right.
If you want to change icon, you need to create a folder called "drawable" in "[my ionic app folder]\platforms\android\res\drawable".
But the trick is: after this you need to quit your livereload mode and execute again CLI command "ionic run android -l -c -s". It's necessary because you need to copy new assets to device.
I only tested with Android device, if you can test with iOS please send a review here.
According to this post on the forum, you can simply set the notification's icon and smallIcon properties. You have to put the files into /platforms/android/res/drawable/ folder. (also mind that the icon has to be started with 'res://somename')
Note: You shall replace ngCordova's notification handling functions, since they are faulty.
In the latest ionic-cli 3,
Copy your icon.png into the following folder.
platforms/android/res/drawable/icon.png
Note that this is in android only.
Once this is done( make sure that the image is a transparent icon),
next step is to initialize this icon in the notification.init function.
Now if we you are using push plugin
do the following;
const pushObj: PushObject = this.push.init({
android: {
senderID: "your_id",
icon: "icon",
forceShow: "true"
},
ios: {
alert: "true",
badge: "true",
sound: "true"
}
});
As you can see that the Only the name of the icon is added not the extenstion.
Once this is done, include a same key value pair in the server side code as well, which pushes the notification into your device.
All will be working well.