Google Cloud Messaging: How to show an icon and group messages - android

I have two questions regarding Google Cloud Messaging:
(My push script is PHP, and my client is Corona SDK.)
PUSH ICON: Currently, my push messages are displayed on the screen with an icon that looks like an inverted triangle with an exclamation mark inside. How do I make it show my own icon? (Can I dictate the icon from the server, or must this be done on the client?)
GROUPING MESSAGES: Currently, if I send three push messages to the phone, they are shown individually in the push list, whereas in other apps, subsequent push messages all replace the previous one, so they only take up one place in the list. How do I accomplish this? Is this the collapse_key value?
Thanks!

First of all, you should have specified "Google Cloud Messaging" (or C2DM in case) in the title of this thread, rather than "Android Push"...
1) If you don't set any custom icon, devices borrow, I don't know why, icons from other installed apps (the icon of Google Talk, sometimes). You can set your own icon from client with the following code:
String app_name = context.getString(R.string.app_name);
int icono = R.drawable.ic_stat_notify;
long time = System.currentTimeMillis();
Notification notification = new Notification(icono, app_name, time);
And you should follow the official Android Design Guideline to design that custom icon, usually designing three versions of the icon (one for devices running v2.2, another for devices running from v2.2 to v3.0 and another for devices running from v3.0).
2) Yes, that's exactly the collapse_key purpose.

Related

Codename One - Show number of unread messages in the app icon

Please look at the Signal icon in this screenshot:
My question is how to obtain the same result in a Codename One app. Suppose that my app has a variable like "int unreadMdg", how can I show the number of unread message in the app icon?
We currently only support this on iOS as it wasn't available on any Android device when we launched the feature and is still arguably flaky on Android.
For iOS support you can set the badge value via push notification (see the developer guide) or by using the API:
if(Display.getInstance().isBadgingSupported()) {
Display.getInstance().setBadgeNumber(unreadCount);
}
This is for IOS
Use this to make it displays a specific number
// Objective-C
[UIApplication sharedApplication].applicationIconBadgeNumber = number;
// Swift
UIApplication.shared.applicationIconBadgeNumber = number

Add "badge notification" for progressive web application (PWA)

I'm developing a progressive web application (PWA) that will eventually send notifications to users.
I already know that I'm able to send push notifications (like in any regular app), as explained in the following blog post: https://developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/?hl=en-us.
However, after having the app in home screen, I would like to add a "hint" to user, letting him know that he has to access the application. A great way to do that is doing something like a "badge notification" (as showed in whatsapp icon on the image below).
Similar badge notification on the Whatsapp icon
Is it possible to add this kind of behavior using progressive web applications?
I believe what you're looking for is the Badging API.
To use the Badging API you can do something like
if('setAppBadge' in navigator && 'clearAppBadge' in navigator){
// set badge
navigator.setAppBadge(badgeCount).catch(error => {
// handle error
});
// remove badge
navigator.clearAppBadge().catch(error => {
// handle error
});
}
Plus, it makes more sense to use it with the Web Periodic Background Synchronization API.
Support
The Badging API is currently supported on Android's Chrome & Samsung Internet Browser and partially supported on Desktop's Chrome & Edge.

Google Nearby notification API not showing new notifications

This is my first post here so please excuse my mistakes.
I am trying to work with Nearby notification. I have added the beacon via "beacon tools" and from my dashboard have added nearby notification. As you can see in the picture, the new notifications are appended at the bottom.
Nearby notification dashboard_img
So in this case, "Title #3" is the latest and that's the one I see in Nearby app when I am next to beacon.
Now, when I tried adding Nearby notifications to my beacons via Proximity API.
I have added the beacon to my project, and I am using
gapi.client.request
to add an attachment to my beacon, using the Proximity beacon API. The add attachment URI:
https://proximitybeacon.googleapis.com/v1beta1/beacons/(BeaconName)/attachments
I am formatting the attachment as such
{
"title": "Example",
"url": "https://www.example.com"
}
When I added 3 notifications via this (one at a time of course), they do show up in my google dashboard for that beacon. But the new ones are stacked on the top, instead of appending at bottom(as seen in the second pic)
Nearby notification dashboard_img
So as you could guess, only the first added notification is visible via Nearby, i.e "Title #1"
Am I missing something here? How do I make the new notifications appear using Proximity API?
PS: I am using Eddystone UID for this.
Update
It seems this was a bug and I had been trying to contact Google in several ways. Finally it reached them and they fixed it today :)
So latest notifications are now automatically displayed & targeting works well.
Kudos to Google engineers working on Nearby!

Push notification from Mixpanel dashboard to Android Cordova app

I am successfully sending Push Notifications from the Mixpanel Dashboard to a Cordova app on both iOS and Android devices, using phonegap-plugin-push.
However, the title and body values entered in the default fields only appear on iOS devices.
For the notification to appear on Android devices, I currently need to include a custom payload in Mixpanels "Custom Data":
{
"title":"Title for Android only",
"body":"Content for Android only"
}
This is an error prone step for any non-technical using Mixpanel to send notifications.
Does someone know an easier way to do this?
The short answer here is that Cordova/Phonegap and similar third party frameworks are not 100% optimized for Mixpanel functionality (although they work pretty great), and as such you'll need to generate separate push notifications for both iOS and Android in your Mixpanel project.
Providing context, all iOS pushes regardless of app deliver a JSON payload to APN using the same keys to deliver their messages (alert, badge, sound). However, the keys that Android apps process for incoming GCM pushes are entirely dependent on how the GCM receiver is established, and therein lies the problem here.
Mixpanel's Android SDK initializes pushes and uses a GCM receiver that is specific to Mixpanel messages, and fully expects its custom keys (mp_message, mp_title) in order to render the notification. The webapp reformats the message input to meet these key requirements (http://bit.ly/1OGgU1y)
However, the Phonegap GCM receiver expects different keys as you've noticed. I'd recommend referring to the phonegap github page in order to get more context into the expected push format and behavior (looks like they expect "title" and "message" as the keys): http://bit.ly/1KDScye
Unfortunately, what this means is that the Android app is not optimized to receive the default, web-app generated Mixpanel pushes, although your iOS one is. Mixpanel's SDKs are intended to maximize capabilities for that platform, and it isn't guaranteed that Cordova or similar JS frameworks will translate 100%.
So to conclude - Creating a message in the Mixpanel push editor will send to iOS, but for Android you'll need to use the custom JSON payload in a separate notification, including keys that the phonegap GCM receiver is compatible with.
If its help to anyone this is how I solved the problem
in phonegap-plugin-push
you need to modify two files
GCMIntentService.java
private String normalizeKey(String key) {
if (key.equals(BODY) || key.equals(ALERT) || key.equals(MP_MESSAGE) || key.equals(GCM_NOTIFICATION_BODY)) { // added MP_MESSAGE
PushConstants.java
public static final String MP_MESSAGE = "mp_message";

Azure notification hub cross platform push

I need to send a push notification to mobile devices that have registered on my notification hub.
The hub is set up to allow windows phone, apple and android devices to register, and I have the appropriate keys and certificates in place. (According to the documentation!)
I am using the latest release of the Microsoft.Azure.NotificationHubs namespace, version 2.16, as advised by the NuGet package manager.
I want to send one message, to all registrations as well as sending a message to a specific device. I can see the devices have all registered correctly with the hub, and have tags that allow me to send notifications to them.
I am trying to use the SendDirectNotificationAsync() method
that takes a Dictionary and a string tag as parameters.
I have also tried the SendNotificationAsync() method that takes a Notification object as a parameter.
Neither method causes a notification to appear on my windows phone with the parameters I have provided, so without an example or more information from the help files, I am stuck.
I cannot find any current examples using these methods and classes.
The examples I have found pre-date the release, and do not show what to send to the notification hub for a cross platform notification to work.
I know these have only just been released, but any help / guidance would be appreciated, as I have reached a complete dead-end with this.
Just a quick update...
Although I never got this to work as I wanted to (as described above), what I ended up doing was to use each platforms native notification as below;
var result1 = await hub.SendMpnsNativeNotificationAsync(windowstoast, mobileDeviceId);
var result2 = await hub.SendGcmNativeNotificationAsync(androidToast, mobileDeviceId);
var result3 = await hub.SendAppleNativeNotificationAsync(iOStoast, mobileDeviceId);
The 'toast' was formatted as per the individual platforms requirements in the documentation.
The 'mobileDeviceId' was the tag that each device registered with the notification hub.
So, clumsy, but it works reliably to achieve the same end.
I still would like to get the cross platform way to work though. Will look into it a bit more when I have time.

Categories

Resources