I am trying to integrate FCM notification in my project. I have Cloud Function backend, and app runs on android.
Below is cloud code to send notification:
exports.notificationTest = functions.database.ref(`/test/childA/childB/status`).onUpdate(event => {
const status = event.data.val();
console.info("Processing notificationTest cloud function")
console.info(`status : ${status}`)
const token = "EnterYourNotificationTokenHere"
const randomNum = Math.floor(Math.random() * 100)
var message = {
notification: { title : "My App", body : `Notification Test ${randomNum}`}
}
console.info(`Sending message on notification token`)
return admin.messaging().sendToDevice(token, message)
.then((response) => {
console.info("Successfully sent notification")
}).catch(function(error) {
console.warn("Error sending notification " , error)
})
})
On native Android app, I receive notification multiple times with interval of few mins.
Here, I have seen notification like this:
Notification Test 30
then after 2,4,8,16,32 mins of previous notification time I again get below message
Notification Test 30
I don't think I need to paste log here, because code is definitely executed just once (as the random number in notification stays the same).
So, why is this happening and how to fix it?
Below is my environment:
Native Android App
Using Android 7
Latest Android Studio Stable
Android Gradle Plugin - 3.1.1
Gradle - 4.1
Firebase-Ui - 3.1.0
Play Services - 11.4.2
Please try to reproduce in environment mentioned above.
I have resolved the issue by renaming my application package name
eg old name: com.xyz to com.xyz2
Using the new name i added this (new) android app to firebase project (it generated new app id). And the notifications started worked as expected (no retry).
But its a shame that I have to rename app package to resolve it. If this app was released in google play then I could not have renamed the app, else no one can get further updates on this app, and it becomes a new app!
It would still be great if some firebase developers could shed light on what is happening.
Recreating firebase project and recreating android project did not help when app name / top level package name were the same. Changing app name and relevant namespaces in existing android project fixed it for now.
Ideally I would like to know the proper fix for this and use the existing name rather than suffixing 2 at the end of app name.
I just had this same issue occur with my Ionic Android app. The same notification repeated after 2, 4, and 8 minutes. This seems to be an issue on the client side because it even happens when sending a message directly from the Firebase console.
I tried several things to fix it and it seems like the only way I could get it to work as intended was to make a new Android project and new Firebase app.
Related
I just started a project in Unity and I integrated FireBase Analytics.
After some problems I was able to get data from IOS and Android devices so I added some custom events.
I followed the instructions from here and I stared to see results in the dashboard . My problem is that I'm not sure if both IOS and Android are sending the events and I don't know how to separate the event in the dashboard. I'm particularly concerned because I'm not sure if I misunderstood this line of the instructions:
The Firebase Unity SDK on Android requires Google Play services, which must be up-to-date before the SDK can be used. The following code should be added at the start of your application to check for and optionally update Google Play ....
I assumed that the following code had to be added ONLY for Android so I didn't add it to IOS. Can you tell me if I had add this code for IOS too? and how can I check the events for every OS?
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available) {
// Create and hold a reference to your FirebaseApp, i.e.
// app = Firebase.FirebaseApp.DefaultInstance;
// where app is a Firebase.FirebaseApp property of your application class.
// Set a flag here indicating that Firebase is ready to use by your
// application.
} else {
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
Thank you in advance
Well, I was looking for all the day and I found that the filter between OS is in the top left corner of dashboard and event tap as well.
I also used the code for both IOS and Android and I started to get custom event in IOS too.
I was asked to develop a sample app integrated with Amazon Pinpoint. Since I am not a pro at developing apps, I decided to follow this simple tutorial and develop the app following the steps described in it. The only differences are that, instead of using an emulator, I executed the project in my own cell phone (a Xiaomi Redmi 4x) and instead of GCM, I used Firebase.
At first, it seemed to work perfectly, but when I moved the app to the background and went back to my homescreen, I could no more receive push notifications from my app. When the app is open and running, everytime I send a push notification a pop-up appears with Title "New Notification" and buttons "Ignore"/"View". But when in background, nothing is visible in my system tray!
Also, if someone knows which part of the code is responsible for this notifications, just warn me and I upload it here.
Okay, so after some tests I made it work (not through console, but through CLI). To do so, I followed some steps I found this question, that took me to two other documents: one from Amazon teaching how to send push notifications through CLI and a simple but very detailed tutorial of phonegap-plugin, the plugin used in our Ionic application to process the pushes.
First of all, replace the phonegap-plugin in your app with the master version avaliable in the github link I sent you.
Then, putting all those information together, I figured out how to write a .json file containing the information we need to send the pushes. Here is a sample of the code I used:
{
"MessageRequest": {
"Addresses": {
"YOUR_DEVICE_ADDRESS_HERE": {
"ChannelType": "GCM"
}
},
"MessageConfiguration": {
"GCMMessage": {
"RawContent": "{\"data\":{\"title\":\"StackOverflow rocks!\",\"body\":\"Am I right?\",\"actions\":[ { \"title\":\"Yes!\", \"callback\":\"app.yes\", \"foreground\":true }, { \"title\":\"No!\", \"callback\":\"app.no\", \"foreground\":false }]}}"
}
}
}
}
As you can see, to change the content in the push notificationm, you'll have to edit it's "RawContent". To do so, use the phonegap-plugin tutorial I sent you and find out how to do the alterations you wish.
Last step: once you updated your plugin version AND saved the code above in a .json file (let's call it test.json), you can send it to your phone oppening command line in the folder containing your .json and writting:
aws pinpoint send-messages --color on --region YOUR_SERVICE_REGION --cli-input-json file:///test.json
This should do the trick! Hope it works for you. If any doubts, just let me know!
I am working on the debug version of an android app. I was able to send both SMS and email invites until I recently installed a different OS on my machine (both Linux). As a result, I also updated Android Studio to the latest version, and imported my old project settings. The rest of the application works fine, I can also start the activity for selecting invites, it displays the message that Invitation was sent, but AppInviteInvitation.getInvitationIds returns 0 length array in onActivityResult.
I tried to add Sha1 and Sha256 to the app in the Firebase console, removed Firebase completely and then added it back to the android project in Android Studio (also removed and added again application and project in the firebase console). So checked and tried most of the solutions on SO, but none seems to work. I am probably omitting something. I am using two google accounts, one for firebase, one for email sending from device.
What else could I verify? Is there any way to dig deeper in Firebase invites in order to find the issue?
The intent:
private void onInviteClicked() {
Intent intent = new AppInviteInvitation.IntentBuilder("MyApp")
.setMessage("Some message of 90 nospecial chars")
// .setDeepLink(createDynamicLink(2))
.setCustomImage(Uri.parse("http://correct url"))
.setCallToActionText("Call to action")
.build();
startActivityForResult(intent, REQUEST_INVITE);
}
Short: keep message short (tested with < 40 chars)
Long: My intent actually contained a 90 character message (no special chars), which was sent just fine before the update. After the update, I need to reduce the length of the message (tested with ~40 characters, none is special), in order for it to be sent.
I wonder what determined this behavior. Things that were changed: java (previously was oracle jdk, now it is the java that comes by default with Android Studio); Maybe also java version. Build tools version 25.0.2 -> 26.0.0.
I have an app working and published in the Apple's app store. We are developing an update with new features and I noticed that the NotificationsRegistrationHandler is not being called anymore on iOS when the user accepts to receive notification (in Android is working fine). Which means the application is not getting the "DeviceToken", so we are unable to send notification. The proc. is very simple, and doesn't look like the issue because it's working for Android devices:
for each
where DeviceType = &DeviceType // enum domain SmartDeviceType
where DeviceId = &DeviceId // Character(128)
DeviceToken = &DeviceToken // Character(255)
DeviceName = &DeviceName // Character(128)
when none
new
DeviceType = &DeviceType
DeviceId = &DeviceId
DeviceToken = &DeviceToken
DeviceName = &DeviceName
endnew
endfor
What I have tried so far:
Generate and install new distribuition certificates and provision profiles.
Rebuild All, Build With This Only, etc.
Tested in "TestFlight" also.
Tested in different devices.
The published app right now is working, however I fear to publish this upgrade and screw up the notification.
I'm using GeneXus Evo 3 U2, .NET generator and Oracle.
Any suggestion how to fix this?
EDIT: Tested with distribuition certificate and sandbox=false, builded for distribuition and sended to testflight, same problem. =/
Have you checked that in the Provisioning Profile (developer.apple.com) the Push Notification service is active:
Enabled Services:
Game Center, In-App Purchase, Push Notifications
I fixed, here is what I did:
Updated from "U2" to "U8". Since "U8" have some OSX and XCode version requirements I updated both to the lastest versions.
Now "NotificationRegistrationHadler" is being called as normal.
I'm having a lot of trouble to get Google Cloud Messaging to work in my Phonegap-based app.
I'm following the instructions that are here.
It uses the PushPlugin, which I installed in my app according to the instructions.
Somehow I get no response after registering, nothing happens (no console.log appears) when I do :
window.plugins.pushNotification.register(
pushSuccessHandler,
pushErrorHandler, {
"senderID":"12345678",
"ecb":"onNotificationGCM"
}
);
var pushSuccessHandler = function(result) {
console.log(result);
};
var pushErrorHandler = function(error) {
console.log(error);
};
var onNotificationGCM = function(e) {
console.log(e);
switch(e.event) {
case 'registered' : {
console.log('android reg id: ' + e.regid);
break;
}
}
};
I setup an API project in Google Developer Console, got a project number that I used as the SenderID, and did all modifications to the Phonegap manifest and config xml files.
My app is not published yet in the Play store.
Is this necessary to get Cloud Messaging working?
And is the code above enough to get a 'reg id', or do I first need to push something from the server, but with what 'reg id' then??
Somewhere I read that the push notifications only work in a Phonegap-app when it is running, or when the notification is clicked, so not when the app is started from the normal icon. I don't understand this however, because aren't the notifications supposed to work when the app is not running?
Push notification will work without publishing, publishing is not required.
Only you have to get Sender ID from developer console.
Sender Id - its project number in developer console
for more detail you can check here
https://github.com/phonegap-build/PushPlugin
I am using it its woreking fine for both android and iOS
Update:
I'm using Intellij IDEA to build the app. When I compiled with phonegap build android the push notifications were working ok.
I had to add the 'android-support-v13.jar' and 'gcm.jar' files as a library in the Project Settings of the IDEA project, to get it working. These libraries need to be added to the Dependencies of the main module with scope 'Compile'.
Before I only added them directly in Dependencies of the module, with Scope 'Provided' but apparently that doesn't work (although it compiled).