Firebase Notification duplicated message
I am facing a serious issue, I am receiving multiple push notifications. I found it generated lots of registration token. These token were made by the same one person, use same desktop, on same network domain.I have try to send test message to those tokens.And those tokens work.
/* 1 */
{
"_id" : ObjectId("5ab330e1a8dbc4623df77853"),
"token" : "d8DtmhvF4_c:APA91bEaGFkn-g2B0-dpOIxfgrvfVbXiB-mLiRPaVfQpGlo4vSYC_FHJfnyQWzLnYmU9CWHqpX1rx1nR7YM7msd5umooOXPXS3dHY9QdQl0NlIkdJ8HQJth1NKPTMy7DhV9HPFrBDQvm",
"agent" : "mozilla/5.0 (windows nt 6.1; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/65.0.3325.181 safari/537.36",
"status" : "enable",
"session" : "89196faa-df82-1e0f-b36b-2854ed3c7b95",
"time" : "2018-03-22 12:28:17"
}
/* 2 */
{
"_id" : ObjectId("5ab9b593403ab4ac0f777a63"),
"token" : "fu-CQUJz8VA:APA91bEn0L-U14Nz0x9nw-Ck3UXbT6CeXpYJZTFBPYCfRH3eGyez3__O6GzA_isY_M_tJiKgofIXrrfhc66tBtiv1ffZ34kuQTe8Qh8oDg43zNo1HSJbQebR1WuMm3P7i28RROTaUpC2",
"agent" : "mozilla/5.0 (windows nt 6.1; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/65.0.3325.181 safari/537.36",
"session" : "89196faa-df82-1e0f-b36b-2854ed3c7b95",
"status" : "enable",
"time" : "2018-03-27 11:08:03"
}
/* 3 */
{
"_id" : ObjectId("5abc6b6ebf33dee27bc0ccd5"),
"token" : "d8DtmhvF4_c:APA91bFUSmTLhe5RHwPBkpUIZCsqzxBjH7yf6HBcmj709xZVG8LaJ07XZTbIZrumb2rKXJ_V9IM6ez6rSKuZqT6iuwRScNEzNQ_CS3Kvcwgp4xrf2VHkYVF5uW7gzF3tq7_izdxwYvvl",
"agent" : "mozilla/5.0 (windows nt 6.1; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/65.0.3325.181 safari/537.36",
"status" : "enable",
"session" : "89196faa-df82-1e0f-b36b-2854ed3c7b95",
"time" : "2018-03-29 12:28:30"
}
/* 4 */
{
"_id" : ObjectId("5acab503a94c4152379c6983"),
"token" : "d8DtmhvF4_c:APA91bFKKQox-DMLej4Mf2zdUfpE3MR0ew48i7lJ-iX7mMskp4KhCJPIhzYsTH88YZXC2FhkLJuUBOsa086Z5OLZ-jU0XFRJz4i2BJI5gWxVa5Npkd5fLsWo4t2nBTdNOZra0SD0gdXb",
"agent" : "mozilla/5.0 (windows nt 6.1; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/65.0.3325.181 safari/537.36",
"status" : "enable",
"session" : "89196faa-df82-1e0f-b36b-2854ed3c7b95",
"time" : "2018-04-09 08:34:11"
}
/* 5 */
{
"_id" : ObjectId("5ad3efbeb98df3232dfc7fb3"),
"token" : "d8DtmhvF4_c:APA91bHsynAV6riwAF4statZxwMt5YJUN19zCd44HRoxp9AOoLwCTG4yrq-aX5UA7ik1UB2H5l30GIYXSqaAqcOYQwyio4jMZF7-SeJ-KR6_LtqlIVNQOuRrvWpW5EAnjWyyhrX3A3rh",
"agent" : "mozilla/5.0 (windows nt 6.1; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/65.0.3325.181 safari/537.36",
"status" : "enable",
"session" : "89196faa-df82-1e0f-b36b-2854ed3c7b95",
"time" : "2018-04-16 08:35:10"
}
Any suggestion will be helpful for me?
See also questions close to this topic
-
Highcharts dual y-axis labeling
I need to have labels in both y-axis of this graph. I managed the one on the left (Million Tonnes) but I can't figure out the one on the left. Right now it says Value but it should say Recycling Rate (%). The idea of course is that it displays in the way as Million Tonnes. In other words, the same alignment. TIA
You can see the code here:
Highcharts.chart('container', { chart: { events: { load: function() { var label = this.renderer.label("SOURCE: CEPI") .css({ width: '600px', fontSize: '1em', color: '#414042' }) .attr({ 'stroke': 'silver', 'stroke-width': 0, 'r': 2, 'padding': -15 }) .add(); label.align(Highcharts.extend(label.getBBox(), { align: 'center', x: 30, // offset verticalAlign: 'bottom', y: 0 // offset }), null, 'spacingBox'); } }, marginBottom: 90 }, title: { text: 'European Recycling Rate of Paper for Recycling', style: { fontSize: '2.5em' } }, subtitle: { text: 'CEPI Statistics - Status as of 2015' }, xAxis: { categories: ['1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015'], gridLineWidth: 1, tickLength: 0 }, yAxis: [{ title: { text: '' } }, { opposite: true, linkedTo: 0 }], series: [{ type: 'column', color: '#8cc640', name: 'Paper & Board Consumption', data: [64.801, 65.576, 65.863, 70.939, 70.937, 71.124, 76.629, 79.788, 82.228, 86.826, 83.878, 84.895, 86.673, 88.918, 89.903, 91.916, 93.165, 90.209, 80.996, 84.873, 83.496, 81.280, 80.161, 81.288, 82.484] }, { type: 'column', color: '#6cbd56', name: 'Recycling inside Europe', data: [26.641, 27.781, 28.611, 31.823, 33.359, 34.597, 36.960, 38.906, 40.544, 43.174, 43.658, 44.800, 45.730, 47.641, 49.011, 50.731, 51.504, 50.184, 46.149, 49.800, 49.108, 48.420, 49.287, 49.511, 49.583] }, { type: 'column', color: '#009347', name: 'Recycling Outside Europe', data: [-0.512, -1.038, -0.598, -0.662, -0.319, 0.358, 0.725, 1.109, 2.339, 1.779, 2.347, 2.436, 3.029, 4.655, 6.587, 7.306, 8.535, 9.853, 12.058, 8.371, 9.406, 9.446, 8.319, 8.561, 9.384] }, { name: 'Recycling Rate', color: '#2f7cba', data: [40.3, 40.8, 42.5, 43.9, 46.6, 49.1, 49.2, 50.2, 52.2, 51.8, 54.8, 55.6, 56.3, 58.8, 61.8, 63.1, 64.4, 66.6, 71.9, 68.5, 70.1, 71.2, 71.9, 71.4, 71.5], marker: { lineWidth: 1, lineColor: '#2f7cba' } }] });
#container { min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto }
<script src="https://code.highcharts.com/highcharts.js"></script> <div id="container"></div>
-
How to open browser choice in mobile on link click from browser?
I need to give choices to the user which browser they want to choose to open in mobile when he clicks on the link in some browser.
For example, if a user opens my webpage in opera mobile browser, then on that page I have to give a link that will give user choice to open that link in another browser. My webpage is using simple HTML and javascript.
This talks about opening your app from a web browser.
Eg: If we open a link from WhatsApp, it gives choices of browsers, or opens in the default browser.
-
Deep search and replace for float values in javascript
I have a nested object and some properties has float values as a string. My objective is to convert those strings to number format. Here is an example object
var myObj = { "value": "text", "params": { "check3": false, "check2obj": { "params": { "value3": 35, "value4": "0.05", "value5": "0.02", "value7": "hello", "local": { "value4": "263.03", "value3": 35, "value2": true, "value1": "hello1" } } } } }
Once parsed, I want this object to look like
{ "value": "text", "params": { "check3": false, "check2obj": { "params": { "value3": 35, "value4": 0.05, "value5": 0.02, "value7": "hello", "local": { "value4": 263.03, "value3": 35, "value2": true, "value1": "hello1" } } } } }
I have tried it with the below function but the string doesn't change to float
function parse(data){ $.each(data, function(key, value){ if(typeof(value)== 'object'){ parse(value); }else{ if(typeof(value) == 'string' && !isNaN(parseFloat(value))){ value = parseFloat(value); } } }); return data; } changedValues = parse(myObj);
-
Firebase error? W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
So I'm fairly new to Java/Android. I tried to make a simple app with a Firebase connection where users can sign up and use that account to log into the app with.
I've managed to make them make an account, it gets stored correctly in the database, however when you try to log in using the account, it doesn't do anything and the following error occurs:
W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
I've googeled around and tried many different solutions, but nothing works.
This is my build.gradle (Module: app)
apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.example.gebruiker.androidchapclient" minSdkVersion 15 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') **implementation 'com.android.support:appcompat-v7:27.1.1'** implementation 'com.android.support.constraint:constraint-layout:1.1.0' implementation 'com.google.firebase:firebase-auth:15.0.0' implementation 'com.google.firebase:firebase-database:15.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' implementation 'com.android.support:cardview-v7:27.1.1' implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.firebaseui:firebase-ui-database:0.4.4' } apply plugin: 'com.google.gms.google-services'
Besides the Firebase error, the bold implementation is also giving me an error which I can't seem to solve.
-
How to increase counter in Fire-base Database?
I have just started Android Fire-base work and working on the Fire-base database. I want to increase count number on button click and set the value to Fire-base database.And after saving data on button click a new Activity is open. when I click on button second count is not increasing.
Please suggest me some solutions.
Here is my code
ValueEventListener eventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { yourRef.child("currentNumber").setValue(counter); counter = dataSnapshot.child("currentNumber").getValue(Integer.class); counter++; Log.d("TAG", "" + counter); } @Override public void onCancelled(DatabaseError databaseError) { } }; yourRef.addListenerForSingleValueEvent(eventListener);
-
Firebase Cloud Messaging not working if on the device there are more than one app bound to a single Firebase Project
I'm studying Firebase SDK and I have a single Firebase project to which I bound many apps; all of these apps include Firebase SDK and its functions (for example: login with FB, login with google, realtime Database, Cloud messaging, etc.).
Now I built an app for testing Firebase Cloud Messaging and I saw that the messages sent by Firebase are not delivered to the device if on the device are installed more than one app (for example app1, app2, app3) bound to the same Firebase project (for example myFirebaseProject).
If from the device I remove all the apps (app1, app2, app3) bound to Firebase project (myFirebaseProject) and then I installed only one app (app1) the messages sent from Firebase are correctly delivered.
Does anybody understand why?
-
Diference betwen Exception Handling and Async Exception handling
I have created a Web API app and don't understand how my Global Exception Handling works. The following code doesn't work:
public void Handle(ExceptionHandlerContext context){ if (context.Exception is ObjectNotFoundException) { var result = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(context.Exception.Message), ReasonPhrase = "Nothing here for you" }; context.Result = new ObjectNotFoundException(context.Request, result); } }
But this works fine:
public override void Handle(ExceptionHandlerContext context){ if (context.Exception is ObjectNotFoundException) { var result = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(context.Exception.Message), ReasonPhrase = "Nothing here for you" }; context.Result = new ObjectNotFoundException(context.Request, result); } }
-
What executes the Python script I see in my browser?
What is playing a Python animation I activate on a remote website? If my browser cannot interpret a local .py file, I would think it also cannot interpret a remote file? Or is it actually the remote website interpreting the script and just sending graphics to me (which would surprise me as there is absolutely no lagging).
The background is this: I visited a website with nice python animations that I could click on and play in my Chrome browser. The site allowed me to to download the scripts as .py files and I would like to edit and play them. However, when I paste the link to such a .py file on my desktop it just opens as a text file. I understand from other posts here that it is because I need to invoke a Python server, which is fair enough. I have searched for python.exe on my own Windows PC, but don't have it. But still I can see python animations on the remote site...
-
how can i build a website that can scrap another website giving it URL?
i already made my own spider using scrapy , and i don't know how to use it in a website so i can control it from the website.
import scrapy class QuotesSpider(scrapy.Spider): name = "quotes" start_urls = [ 'http://quotes.toscrape.com/page/1/', 'http://quotes.toscrape.com/page/2/', ] def parse(self, response): for quote in response.css('div.quote'): yield { 'text': quote.css('span.text::text').extract_first(), 'author': quote.css('small.author::text').extract_first(), 'tags': quote.css('div.tags a.tag::text').extract(), }
-
Android Notifications with customized appearance
As of now, I am using Firebase Cloud Messaging as my app's notification system. From my understanding, even the largest companies use GCM, which is now being replaced with FCM. I am stuck, however, with the limitations imposed by sending things as a "notification" pay load.
Firebase recieves data messages in OnMessageRecieved, and I am able to get my exact desired behavior through using this. However, for the past three months I noticed that my app's notifications were simply not working because data payloads aren't received when the app is in the background/ inactive. This is very frustrating as the only workaround I have found to actually send notifications that alert users is through sending notification payloads.
I don't know how to get my desired behavior with the notification payload as I have been with data payload, but I realize that having notifications display perfectly when the app is in the foreground is pointless if they don't display at all when the app is in the background.
What I'm wondering, and what I'd really appreciate guidance on, is if somebody could recommend a way to display notifications with my desired style rather than the default Firebase notification style. Just to elaborate, I currently have a fully functional system of allowing users to respond to messages through the notification and without opening the app, but only through the data payload.
I know there is a way to somehow send notifications in a customized fashion (adding intents, buttons, etc) when the app is in the background or not running because this is done by Facebook, WhatsApp, and many other apps on the market. I am aware of something called AlarmManagers, but unsure of how I could use them to get my desired behavior, or if this is what people use anyways.
Thank you, and please let me know if there is a way to customize the payload when the app is in the background or inactive, through onMessagesRecieved or any other methods. As of now, the only other solution would be to somehow send the message's contents to a service, but I've faced issues where services could not display notifications in the background without crashing the app and without being very hacky.
-
why postman send Notification with string only to my phone?
when I send notification without string in data its send to all devices but when I use the activity that carried the string (with URL) its send only to my phone (galaxy 9 - android 8 - is it the reason?) off course I use postman software
when I use the -
click_action.equals("SPLASH")
- that were the problem this is the class that is use to get the message and pass it to the next activity:public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService{ private static final String TAG = "FirebaseMessagingServic"; public FirebaseMessagingService() { } @Override public void onMessageReceived(RemoteMessage remoteMessage) { // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { Log.d(TAG, "Message data payload: " + remoteMessage.getData()); try { JSONObject data = new JSONObject(remoteMessage.getData()); String jsonMessage = data.getString("extra_information"); Log.d(TAG, "onMessageReceived: \n" + "Extra Information: " + jsonMessage); } catch (JSONException e) { e.printStackTrace(); } } // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { String extra_info = remoteMessage.getData().get("extra_information"); // get extra info String title = remoteMessage.getNotification().getTitle(); //get title String message = remoteMessage.getNotification().getBody(); //get message String click_action = remoteMessage.getNotification().getClickAction(); //get click_action Log.d(TAG, "Message Notification Title: " + title); Log.d(TAG, "Message Notification Body: " + message); Log.d(TAG, "Message Notification click_action: " + click_action); assert click_action != null; sendNotification(extra_info,title, message, click_action); } } @Override public void onDeletedMessages() { } private void sendNotification(String extra_info, String title, String messageBody, String click_action) { Intent intent; final Handler handler = new Handler(); if (click_action.equals("MAIN_ACTIVITY")) { intent = new Intent(getBaseContext(), MainActivity.class); intent.putExtra("MAIN", "MAIN"); startActivity(intent); } else if (click_action.equals("SPLASH")) { intent = new Intent(this,SplashNotifWeb.class); intent.putExtra("extra_information",extra_info); // putExtra some info to pass with the notification intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); } else if (click_action.equals("MONDIAL")) { intent = new Intent(this,MondialActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); } else if (click_action.equals("EBAY_ADVER")) { intent = new Intent(this,ebayActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); } else { intent = new Intent(this, MondialActivity.class); 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.drawable.alertlogo) .setContentTitle(title) .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); } }
-
Inconsistent results from Firestore Cloud Functions
I have a Cloud Function setup on Firebase that involved checking different parts of the Firestore Database and then sending a message via Cloud Messaging
Below is the JavaScript for the function in question:
const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().Firebase); var db = admin.firestore(); exports.newMemberNotification = functions.firestore .document('Teams/{teamId}/Waitlist/{userId}').onDelete((snap, context) => { // get the user we want to send the message to const newValue = snap.data(); const teamidno = context.params.teamId; const useridno = newValue.userID; //start retrieving Waitlist user's messaging token to send them a message var tokenRef = db.collection('Users').doc(useridno); tokenRef.get() .then(doc => { if (!doc.exists) { console.log('No such document!'); } else { const data = doc.data(); //get the messaging token var token = data.messaging_token; console.log("token: ", token); //reference for the members collection var memberRef = db.collection('Teams/'+teamidno+' /Members').doc(useridno); memberRef.get() .then(doc => { if (!doc.exists){ console.log('user was not added to team. Informing them'); const negPayload = { data: { data_type:"team_rejection", title:"Request denied", message: "Your request to join the team has been denied", } }; return admin.messaging().sendToDevice(token, negPayload) .then(function(response){ console.log("Successfully sent rejection message:", response); return 0; }) .catch(function(error){ console.log("Error sending rejection message: ", error); }); } else { console.log('user was added to the team. Informing them') const payload = { data: { data_type: "team_accept", title: "Request approved", message: "You have been added to the team", } }; return admin.messaging().sendToDevice(token, payload) .then(function(response){ console.log("Successfully sent accept message:", response); return 0; }) .catch(function(error){ console.log("Error sending accept message: ", error); }); } }) .catch(err => { console.log('Error getting member', err); }); } return 0; }) .catch(err => { console.log('Error getting token', err); }); return 0; });
The issues I have with this are:
- The code runs and only sometimes actually checks for the token or sends a message.
- the logs show this error when the function runs: "Function returned undefined, expected Promise or value " but as per another Stack Oveflow posts, I have added return 0; everywhere a .then ends.
I am VERY new to node.js, javascript and Cloud Functions so I am unsure what is going wrong or if this is an issue on Firebase's end. Any help you can give will be greatly appreciated