Notifications not appearing in background state and killed state of an app - android

I'm trying to push notifications to the end-users of the app when post is uploaded. It works fine when the app is in foreground but doesn't show up when then the app is in background or killed. Is there any way to show the notifications when the app is killed or running in the background.
Here is the node.js code which i'm using
const functions = require('firebase-functions');
let admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendPush = functions.database.ref('/promos').onWrite(event => {
var topic = "deals_notification";
let projectStateChanged = false;
let projectCreated = false;
let projectData = event.data.val();
if (((event.data.numChildren())-(event.data.previous.numChildren()))>0) {
let msg="notification arrived"
let payload = {
notification: {
title: 'Firebase Notification',
body: msg,
sound: 'default',
badge: '1'
}
};
admin.messaging().sendToTopic(topic, payload).then(function(response) {
// See the MessagingTopicResponse reference documentation for the
// contents of response.
console.log("Successfully sent message:", response);
}).catch(function(error) {
console.log("Error sending message:", error);
});
}
});
and here is the MyFirebaseMessageService:
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyFirebaseMessageService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.e("notification---",remoteMessage.getNotification().getBody());
sendnotification(remoteMessage.getNotification().getBody());
}
private void sendnotification(String body){
Intent intent = new Intent(this, MainActivity.class);
// use System.currentTimeMillis() to have a unique ID for the pending intent
PendingIntent pIntent = PendingIntent.getActivity(this, (int)
System.currentTimeMillis(), intent, 0);
// build notification
// the addAction re-use the same intent to keep the example short
Notification.Builder n = new Notification.Builder(this)
.setContentTitle("Best Deals")
.setContentText(body)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pIntent)
.setAutoCancel(true);
NotificationManager manager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, n.build());
}
}
Thanks.

I am sure the code is perfect. But there might be some problem with the device you are testing.Please try to test the code with some other device.

if the problem is that onMessageReceived() is called only when the app is in foreground, and when it's in background a notification is displayed but your method is not called... than that's working correctly. See the documentation:
Use notification messages when you want FCM to handle displaying a
notification on your client app's behalf. Use data messages when you
want to process the messages on your client app.
Read more here: https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
You are sending a notification-message. instead you should send a data-message
If the problem is different: when the app is in background nothing happen, it might be a problem of your device. See Push notifications using FCM not received when app is killed android

Related

intent with FCM not working when app is in background(android)

I am using FCM to push notification. I am passing intent to launch new activity when notification is clicked.when app is in foreground,app works fine and intent launch new activity, but when app is in background, it does not launch new activity but launch instance of default activity.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Displaying data in log
//It is optional
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
//Calling method to generate notification
sendNotification(remoteMessage.getNotification().getBody());
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, SecActivity.class);
intent.putExtra("started_from","notification");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Firebase Push Notification")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
Hope you are trying to launch the mainactivity when the message is received. When the app is resumed from background your current activity is getting cleared.
From the documentation for FLAG_ACTIVITY_CLEAR_TOP:
If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.
Try removing this flag.
I too had this same problem but i managed to have it fix with this ,
In your default activity mentioned in the manifest do this in the onCreate
if (bundle != null) {
if ((String) bundle.get("tag") != null) {
String tag = (String) bundle.get("tag");
if (tag.equals("abc")) {
Intent intent = new Intent(SplashActivity.this, MessageDetailsActivity.class);
startActivity(intent);
} else if (tag.equals("def")) {
openSpecificActivity(tag, (String) bundle.get("id"));
}
} else {
Intent i = new Intent(SplashActivity.this, HomeActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
}
i got a solution for that.
just put below code in oncreate method of launcher activity.
if (bundle != null) {
String value = bundle.getString("key");
if (value != null) {
startActivity(new Intent(MainActivity.this, secActivity.class));
}
}
when app is in background or killed,FCM will not call onmessagerecieved method,but it will send data to system tray to display notification.so datapayload(sent from fcm console) will not be handled by onmessagerecieved method.when user click on notification,it will launch default activity of app and datapayload will be passed by intent .so making change in oncreate method of launcher activity(as above)we can get datapayload even when app is in background or killed.(ex key is sent by fcm console).when app is in foreground datapayload and will be handled by onmessagerecieved method of fcm service.
Based upon Antinio's answer
https://stackoverflow.com/a/37845174/4454119
Why is this happening?
There are two types of messages in FCM (Firebase Cloud Messaging):
display-messages: These messages trigger the onMessageReceived() callback only when your app is in foreground
data-messages: Theses messages trigger the onMessageReceived() callback even if your app is in foreground/background/killed
Firebase team have not developed a UI to send data-messages to your devices, yet.
So you need to use data-messages..
In FCM you have two types of messages
Notification Messages
Data Messages
Use notification messages when you want FCM to handle displaying a notification on your client app's behalf. Use data messages when you want to process the messages in your client app.
If you need to process your message before sending it to the system tray, it's better to use Data messages, as for these types of messages, the callback first reaches the onMessageRecieved method before going to the system tray.
Use this:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
IN YOUR SERVICE
"to": token,
"notification": {
"title": "Title,
"body": "Body"
},
"data" : {
"update": "yes"
}
IN ANDROID KOTLIN
val intent = Intent(this,MainActivity::class.java)
intent.putExtra("update","yes")
......

App connected to FCM not receiving notification from AWS SNS

I've connected an Android app to Google Firebase Cloud Messaging service (FCM) following this guide,
and I've followed this answer to setup the connection between FCM & AWS SNS.
I could successfully receive message sent from FCM console but not from AWS SNS console.
The message delivery status logged on AWS showed SUCCESS for every message I've sent while no notification was shown on my device.
Is there a way to check what's going on?
I faced the exactly the same problem, message from Firebase with device token works but somehow message from SNS to Firebase is not delivered.
I did develop iOS app as well, and at that moment, just sending "brabra" delivered message to iOS. However, FCM only accepts particular message format to test it from AWS SNS console.
Here is the example format of successful delivery of message to Android through SNS and FCM.
{
"GCM": "{\"notification\": { \"body\": \"Sample message for Android endpoints\", \"title\":\"Hello world\" } }"
}
The point is that we have to amend to "notification", not "data", and should have body and title in the notification.
The problem here is that AWS SNS sends what Google calls data messages.
With FCM you can send two types of messages - notifications and data. Notifications get displayed automatically by FCM while data messages do not. More on this here: https://firebase.google.com/docs/cloud-messaging/concept-options
Data messages that come in from SNS still can be handled - even if your app is in the background - by extending FirebaseMessagingService and overriding it's onMessageReceived method. More on this here: https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService
I assume you would want your AWS SNS messages to mimic the notifications experience, namely:
See them pop up when the app is in the background
Have your text displayed in the notification
When the app activates you want all of the messages cleared out from
the drawer
To achieve this you'll want to do three things.
Firstly - you'll want to start tracking if your app is currently visible or not. The details on how to reliably detect this you can find here: https://stackoverflow.com/a/18469643/96911
Secondly - you'll want to handle data messages from AWS SNS by posting a notification, but only when your app is in the background:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
static protected int id = 0;
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (!MyApplication.isActivityVisible()) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentTitle(getString(R.string.app_name))
.setSmallIcon(R.drawable.notification_icon);
String message = remoteMessage.getData().get("default");
mBuilder.setContentText(message);
Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.notify(id ++, mBuilder.build());
}
}
}
And lastly - you'll want to clear out all of the notifications from the drawer when the user clicks on one of them. Combined with the visibility tracking I linked just above the activity that responds to the notifications should have the following onResume method:
#Override
protected void onResume() {
super.onResume();
MyApplication.activityResumed();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.cancelAll();
}
It's been a long time since you asked this question but it was so painful for me to get to the bottom of this I decided to answer anyway. I hope this helps you or somebody tearing their hair out trying to make this thing work (cause making iOS work was a breeze, sheesh).
You can use this video tutorial https://youtu.be/iBTFLu30dSg with English subtitles of how to use FCM with AWS SNS step by step and example of how to send push notifications from AWS console. It works well for me and I successfully received push notification from SNS console and from my code on the mobile device
Simply using this JSON format:
{
"GCM": "{ \"notification\": { \"body\": \"Sample message for Android endpoints\",\"title\": \"Sample message for Android endpoints\"}}"
}
To get the Data from AWS SNS Console follow the below step:
1) Add the Project in FCM and Use Legacy server key for AWS SNS.
2) Get the Device token by using the below code:
String deviceToken = FirebaseInstanceId.getInstance().getToken();
3) Implement the below code in your application
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
#Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
// TODO: Implement this method to send token to your app server.
}
}
4) Override onMessageReceived() its invoke when notification is received:
public class AppFirebaseMessagingService extends FirebaseMessagingService {
static protected int id = 0;
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//remoteMessage.getNotification().getBody()
if (remoteMessage.getData().get("default").length() > 0) {
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri ringNotificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("ApplicationName")
.setContentText(remoteMessage.getData().get("default"))
.setAutoCancel(true)
.setSound(ringNotificationSound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id++, notifyBuilder.build());
}
}
}
When We get the Notification from AWS SNS Service then we use remoteMessage.getData().get("default") for reading the message from AWS.

Android Firebase notifications (FCM)

I am using FCM in my app. I followed the Firebase documentation and all seems to be working as expected.
I am able to receive message notifications when the app is killed, in background and in foreground.
Now I want to give full control the user by adding some app preferences.
The user can disable all notification from the app settings
The user can change notification ringtone from the app settings
I have an idea on how to do it when the app is in killed or in the foreground. I am thinking of accessing the sharedprefs in my FirebaseMessagingService to see if the app should show the notification and check what ringtone to use. Unless there is a generic way to set those parameters, like "unsubscribing" from all notification or changing the app default notification ringtone which I am not aware of?
However I have no idea how i can do it for the notifications received when the app in is the background since the notifications are delivered to the device's system tray.
Anyone has any idea or can point me to some documentation... I am not finding any info on this?
By default, notifications affect every user. If you'd like to allow users to opt-out of all notifications (or certain subsets of notifications), you should use topic messaging: by default, you'd call subscribeToTopic() for all users and if they opt-out of notifications, you'd call unsubscribeToTopic().
By sending a notification to a topic, only the subscribed users will receive it.
The notification payload support documentation explains how to include a sound parameter to override the ringtone - on Android, that can be any sound bundled in the app's res/raw directory.
It should be noted that neither of these features are supported in the Console, but require that you create your own Firebase Cloud Messaging Server
As firebase notification service is having 2 object 1st is "data" and 2nd is "notification", when you are sending push from firebase console it sending data in "notification" object. When u handle the notification in FirebaseMessagingService.class you are creating a custom notification with NotificationBuilder. When App is in background you wont be able to create notification from "notification" object. so, your custom made notification wont be appear in notification tray, You need to push a notification from your backend and send notification contents in "data" object. You will be able to customise your notification every time.
please refer this for more : https://firebase.google.com/docs/cloud-messaging/android/send-multiple
The user can disable all notification from the app settings.
You can use shared preferences as you stated yourself. As far as a generic method is concerned you should look into #ianhanniballake 's answer.
The user can change notification ringtone from the app settings
For default ringtones refer to this link. The 3rd answer in this link also explains how to bring the sound selector from settings activity of your app. If you want custom sounds refer this.
Of course, you'll have to store user preferences so that you don't ask the user each time to select a sound.
And one more thing since you are using a service so you need not access shared preferences each and every time to find which sound to play, you can store the choice in any variable. Whenever there is a change of notif-sound by the user, you can either set a listener or {stop service -> update preferences -> restart service}. Make sure every time the service starts it reads the preferences.
In this AndroidHive tutorials you can find how we change Ringtone for particular app and how to deal with notifications when app is in foreground and app is in background.
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
......
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
handleNotification(remoteMessage.getNotification().getBody());
}
}
When notification type message is sent, firebase automatically shows the notification when the app is in background. If the app is in foreground, handleNotification() method handles the notification message.
private void handleNotification(String message) {
if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {
// app is in foreground, broadcast the push message
Intent pushNotification = new Intent(Config.PUSH_NOTIFICATION);
pushNotification.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);
// play notification sound
NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
notificationUtils.playNotificationSound();
}else{
// If the app is in background, firebase itself handles the notification
}
}
Here you handle custom Notification Sound-
// Playing notification sound
public void playNotificationSound() {
try {
Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
+ "://" + mContext.getPackageName() + "/raw/notification");
Ringtone r = RingtoneManager.getRingtone(mContext, alarmSound);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
}
Firebase will not call your onMessageReceived when your app is in background or killed, and you can't customise your notification. System generated notification will show.
to make firebase library to call your onMessageReived in every cases
a) Foreground
b) Background
c) Killed
you must not put json key "notification" in your request to firebase api but instead use "data", see below.
For example following message will not call onMessagereceived()
{
"to": "/topics/test",
"notification": {
"title" : "title",
"text": "data!",
"icon": "ic_notification"
}
}
but this will work
{
"to": "/topics/test",
"data": {
"text":"text",
"title":"",
"line1":"testline",
"line2":"test"
}
}
see this link:https://firebase.google.com/docs/cloud-messaging/concept-options
it has a detailed description of firebase message type
For example:
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
if(remoteMessage.getData().get("state").toString().equals("Request")){
sendNotification(remoteMessage.getData().get("body").toString(), remoteMessage.getData().get("message").toString(), remoteMessage.getData().get("state").toString(),Activity_name.class);
}
}
private void sendNotification(String messageBody, String data, String state,Class<?> activityCompat) {
int requestID = (int) System.currentTimeMillis();
Intent intent = new Intent(this, activityCompat);
Bundle bundle = new Bundle();
bundle.putString("message", data);
bundle.putString("state", state);
intent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getActivity(this, requestID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.small_logo)
.setContentTitle("Title")
.setContentText(messageBody).setContentIntent(pendingIntent)
.setAutoCancel(true)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(messageBody))
.setTicker(messageBody);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
Notification notification = notificationBuilder.build();
notificationManager.notify((int) Calendar.getInstance().getTimeInMillis(), notification);
}

Android Notification not shown

I wrote an IntentService for GCM Push Notifications.
I receive the Messages but something's wrong with displaying my Notification to the user.
Here's my Code:
import com.google.android.gms.gcm.GoogleCloudMessaging;
import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.util.Log;
public class GcmIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
public GcmIntentService() {
super("GcmIntentService");
}
public static final String TAG = "GCM test";
#Override
protected void onHandleIntent(Intent intent) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!intent.getExtras().isEmpty()) { // has effect of unparcelling Bundle
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
sendNotification("Send error: " + intent.getExtras().toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
sendNotification("Deleted messages on server: " + intent.getExtras().toString());
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// Post notification of received message.
sendNotification("message:\n" + intent.getStringExtra("message"));
Log.i(TAG, "Received: " + intent.getExtras().toString());
}
}
// Release the wake lock provided by the WakefulBroadcastReceiver.
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private void sendNotification(String msg) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notif)
.setContentTitle("My notification")
.setContentText(msg);
Intent resultIntent = new Intent(this, PopupMessageActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(PopupMessageActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
}
I don't see the mistake. I mean, I copied the code from the Androids developer guide.
The only thing that this code does, is that the small icon (in this case "ic_notif") is showing in the notification-bar of the phone.
But there's no Text or Notification that pops up to the user.
I use android-studio.
My debug device is an huawai u8666e with android 4.0.3 (API 15).
At least i want this API level to be my minimum requirement for this app.
What you are seeing is normal designed Android behaviour for versions before Lollipop.
The design logic is that this method creates a cleaner interface and will not interrupt the user's current actions by placing a popup in front of their face. (there is a lot of debate over which method is better - iOS popups vs Android notifications).
Lollipop changes this slightly by creating a small popup at the top of the device window when a Notification is created.
If you really want to force a popup dialog to be shown, you should be looking at designing a "full screen" Notification.
See the Android Developer docs:
Notication.Builder.setFullScreenIntent(Intent)
Using this method, you can create a new Activity with any custom layout you want, and launch that instead of placing the Notification in the status bar.
(full implementation of a full screen notification would be beyond the scope of this post)
I would recommend against forcing full screen notifications except in rare cases, such as an Alarm Clock, or Phone Call app. I would, instead, recommend that you stick to the way Android was designed and work with the OS.

Default push notification sound in Worklight 6.1

I'm using Worklight Push Notification but on Android the push comes with no sound. I want to enable default sound (and LED if possible).
I'm using the sample push notification example code.
var notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});
I also tried to assigning a value like notification.GCM.sound = "true" or notification.GCM.sound = "default" but it is playing continuous sound on some devices.
To accomplish this you will have to modify your app. Worklight will generate a skeleton class in your Android project, GCMIntentService.java
In order to add sound and flash the LED notification light, you will have to override the notify methods in the GCMIntentService class. Your file will look like this:
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
public class GCMIntentService extends
com.worklight.androidgap.push.GCMIntentService {
#Override
public void notify(Context context, String alert, int badge, String sound,
Intent intent) {
super.notify(context, alert, badge, sound, intent);
// call helper method
notifyLightAndSound(context);
}
#Override
public void notify(Context context, String tickerText) {
super.notify(context, tickerText);
// call helper method
notifyLightAndSound(context);
}
private void notifyLightAndSound(Context context) {
// Get the default notification sound
Uri notification = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// build a notification with the light and sound
// LED will be on for 1000 ms and off for 800 ms until you turn on your
// screen
Notification n = new Notification.Builder(context)
.setLights(Notification.DEFAULT_LIGHTS, 1000, 800)
.setSound(notification).build();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// play sound and flash LED
mNotificationManager.notify(4, n);
}
}
This will flash the LED and play the default notification sound of your phone "different based on each phone".
I hope this helps to answer your question.
LED notification is not available.
See here: Led not working on Android using Unified Push Notification of worklight (6.0.0.2)
To use a custom notification sound (see supported media formats):
If the folder does not exist already, add a folder named raw under the existing native\res folder in yourProject\apps\yourApp\android\native
Place the sound file in the raw folder
To use default notification sound, try sending it empty:
notification.GCM.sound = "";

Categories

Resources