How to use image and vibrate_timings with my fcm message - android

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

Related

Is there a way to dynamically load Material Icons in native android (Java)?

Recently i was able to dynamically load Material Design Icons in Flutter by using the flutter_icons/flutter_icons.dart
// First Approach
Icon icon = new Icon(Icons.settings);
// Second Approach
icon = new Icon(MaterialIcons.getIconData(Model.dynamic_icon_name);
Flutter Screenshot
This got me thinking if i could do something similar using a native android approach, with something like
// Glide Theoretical Example
Glide.with(context.getApplicationContext())
.asBitmap()
.load(MaterialIcons.getIconData(Model.dynamic_icon_name))
.apply(new RequestOptions().fitCenter())
.into(iconView);
I think it would be interesting to know, since i think could provide some advantage that a developer would not need to bundle those assets with the app
There was no effective way of handling this natively on Android, so the solution i ended up going with was having the server host these icons and i could just serve them down using Glide like this.
Step 1: Backend setup
Download the png assets for the icon of your choice, ie: the thumbs_up icon from this Material Icons link
Now you can go ahead and unzip the image assets into your server's assets folder, in my case this was in my public folder of the server since i was using a Laravel backend. In the end my icons resided in the path public/material-icons/thumb_up_black.png and made sure to keep a consistent naming convention public/material-icons/{icon_name_color}.png this was the vital point since i needed to reference these assets again.
Now we can link the icon with the respective item
Server side
...
// Creating the item
new Item::create([
'name' => 'Like-able item',
'icon' => 'thumb_up_black',
]);
...
List items API endpoint result
[
{
"name": "Like-able item",
"icon_url": "https//server-name.fancy/thumb_up_black.png"
},
{
"name": "Like-able item #2",
"icon_url": "https//server-name.fancy/thumb_up_black.png"
},
....
]
Step 2: Client Setup (Android app)
Once i have consumed the API data and about to display the items, i can use Glide to accomplish this.
ItemModel item = new ItemModel(itemDataFromServer);
Glide.with(context.getApplicationContext())
.asBitmap()
.load(MaterialIcons.getIconData(item.icon_url))
.apply(new RequestOptions().fitCenter())
.into(iconView);
This was finally how i was able to solve this problem, the nice thing with this implementation was that from our three client apps (Android, iOs and Web) we could use the same if not similar method to display accordingly.

Getting "Contents hidden" as replacement in custom layout public notification

I would like to set the italic "Contents hidden" message for a public notification manually.
Android seem to set "Contents hidden" automatically if only a VISIBILITY_PRIVATE notification without a public counterpart is presented.
Here, the setContent-parts are automatically replaced.
For an example from K9mail see screenshot 1.
However, I would like to use a custom layout for the public notification while letting the notification look similar (i.e., "Contents hidden").
It is a notification for a music player, which should provide buttons for pause and play next songs.
So, how can I either
access the (localized) value for "Contents hidden" that Android is actually using (not implementing it manually) or
tell Android to replace all "setContent"-parts automatically as if I would not provide a public notification.
Any suggestions?
For the sake of completeness - the issue is related with this pull request: https://github.com/gateship-one/odyssey/pull/120
Pretty simple just use:
String foo = mContext.getString(android.content.res.Resources.getSystem().getIdentifier("notification_hidden_text", "string", "android"));

FCM - How to get icon to be valid?

I am sending a Firebase Cloud Messaging notification to my Android app, but the icon on the notification is not showing correctly. its on nexus I'm having the trouble (KitKat).
and im using the following sdk:
minSdkVersion 19
targetSdkVersion 24
The image (.png) is a logo I am pulling from the drawable folder and it looks like this:
But now when I use it in my notification it looks like this:
Keep in mind I am sending the notification using an API call like this:
https://fcm.googleapis.com/fcm/send
and the post body looks like this:
{ "notification": {
"title": "Your Title",
"text": "Your Text",
"click_action": "OPEN_ACTIVITY_1"
},
"data": {
"keyname": "some data item name "
},
"to":"eZm-5IM8dkE:APA91bFkC9kZSgZblDr_4JBB-MNOCkITsRGSECykFzXQE70zzM8rShP66pPYIX4iBio3V9sN1Go1q4o6dGhybm6SPRio3asC-6NIltzQfc0ZlmWrexxxxxxxxxxxxxxxiHygCx2y"
}
I noticed I am not setting the icon anywhere, but I don't think that's the issue. Notice how its a parallelogram in both images, so I think its just processing it differently. What am I doing wrong?
also note in the Android Manifest, I have set the following:
<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/mylogo" />
FCM is showing your icon correctly but Android (not FCM) is changing the icon color to white.
This is the standard behavior of Android and is documented here:
https://developer.android.com/about/versions/android-5.0-changes.html#BehaviorNotifications
(see the last paragraph under Notifications > Material design style)

My custom icon doesn't appear in the 'local' push notification (Android)

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.

How to set large image in ionic.io -push notification

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.

Categories

Resources