Firebase Cloud Messaging not working on some devices - java

I have a problem with sending push notifications from server via FCM.
So at first everything was working fine after adding push notifications.
I had to change the package name of an android app so I added new app on Firebase with new package name and I have downloaded new json file, and changed the name in manifest file and gradle.
After doing it, I noticed that on some smartphones these notifications aren't working and on others they work :/
When I'm using only Firebase to send push notification (the firebase console) - it works. But when I receive the push notification from server on one phone, on another I don't.. I am updating the regId in my database and all notifications on my phone are turned ON. I thought that maybe the problem is that I have 2 apps in one project in firebase, so I made new project and again downloaded json file but it is the same as earlier.
Have anyone had this kind of problem or anyone knows what could solve it and make it work again? :/

Really depends on device you were trying it on.
if the google play services is out of date you could try updating it from playstore.see if that fixes the problem.
if it has no google api/Playstore (so no amazon products and some none market devices)
push messaging does not work along with authentication. The realtime Data base still works but fires off an error in logcat.
ive been pulling my hair out for weeks trying to figure it out.. thought it was my code.. so i sent the firebase team a email to ask. They confirmed that there was no fix for this at the present time.. hope this helps

Related

Notification in Android Studio y Firebase Database when the app is closed [duplicate]

I am creating an Ionic 2 app with firebase and I need a way to listen to database changes (specifically on child_added) when the app is closed (I.e. in foreground,background and killed)
Basically, I want to use WebRTC to make calls within the app like whatsapp and I am following this post - https://websitebeaver.com/insanely-simple-webrtc-video-chat-using-firebase-with-codepen-demo
However, the only thing that puzzles me is how it will work when the app is closed. Can anyone please help me understand?
Thanks!
It's not possible to actively listen to database changes using the Firebase client SDK in exactly the same way that you can when your app's code is running.
If you want your app to receive information about changes to your database, you can instead use Firebase Cloud Messaging to send your app a notification with a small payload that contains information about the change. When your app receives the notification, it can then make a decision about what to do. There are some limitations with web support, so be sure to read about that.
Also look into Cloud Functions for Firebase to make it easier to write some server side code that can trigger in response to a database change and send a notification when those changes happen.

Save chat messages with closed app

Good evening!
I'm developing a chat application that looks like WhatsApp. I need the received messages to be saved on the user's mobile device. Until then everything was ok, because I was saving the messages when the user received the push notification on the mobile, but the problem happens when the application is closed because when the application is closed the push notification does not trigger the received push event (I am using the Onesignal to send the push).
I'd like to know how I can do this, ie get a notification and process it even with my closed application. I think it has to do this because Whatsapp does this and also Spotify also does it when I connect the Spotify to another device it automatically forces the opening of the application on my cell phone.
So my question is, how do I handle an event with the application closed or even force it to open according to a particular event?
I'm using the technology of Ionic 1 and Angular.js. For push notification I am using the OneSignal provider.
Thanks in advance for your attention and hope someone can help me. Thank you!
I'm fairly sure you won't be able to do what you're describing. There is a 'background push' feature introduced in iOS 9 that lets an app receive a payload triggered via push even when it is closed, but that's more for downloading (for example) a new edition of an online magazine, rather than lots of messages.
The difference betwen those two use cases is that if you're subscribed to a magazine, you might want the latest issue to download automatically whilst you have an internet connection, so that you have the issue to read when you're flying/on the train or whatever. A chat app... is pretty useless if you're not connected to the internet anyway, so there's no urgent need to have new messages 'pre-downloaded'
Even if you could do it, I don't think it would be best practice as there's too many scenarios where people won't have internet anyway so you're going to be left without the full message history when a user opens the app (not to mention push notification delivery is not tracked or guaranteed), so you're going to have to do some sort of query when the app launches to download new messages anyway.
If you've got code already that checks and downloads new messages while the app is open, that's great. But if its closed, you'll just need to run some sort of query on launch to download unread messages or something like that

Android GCM Registration is failing

I am working on Google cloud messaging service in my android app. For this I need to register my android app to GCM server.
The gcm registration is failing.
I have checked:
The gcm register code is Async call.
The sender id (project id) is correct.
The manifest file is as per the google doc. http://developer.android.com/google/gcm/client.html
My device has google account set up.
I have tried both the cases - add google-play-services jar and import it as project.
I even went on to specify the version number (com.google.android.gms.version) in manifest as per this http://developer.android.com/google/play-services/setup.html#Setup
Where and why would this be failing?
When I catch the exception, exception cause is NULL.
I had done a demo app for this GCM part and it was working fine. I had used Eclipse with JellyBean SDK.
I extended this project to make the current app - package stucture remains same. But now am on Kitkat SDK.
I used the same Sender Id as before to register with GCM. It failed giving null id. I created new project at cloud console and used its project number as sender id. Still same error. Registration Id is null. I don't think Sender Id should be any issue.
Any help would be appreciated.
So is GCMRegistrar Class giving out, that it failed to register?
i think it could be your Manifest file - check everything correctly until you are really sure you did everything right.
I had an other problem when i implemented GCM into my Project. It was giving out "Regestration OKay" but the REG_ID from GCM Server that i needed to read out, was giving me an Empty (not NULL) it was empty LOL.
I moved my MainActivity (where the regestration happens) in the "original" package of my project and it worked.
please follow Push Notification via GCM
if key for browser apps doesn't work, then create key with ip locking and replace it into your config.php file, it will sure work.
please also check whether your client side code works properly or not on this site
I am getting the GCM Registration Id now. I made two changes.
Removed debuggable=false from Manifest file. Wrote a code in the activity to check for version of Play Store.
So conclusion, it was the issue with play store version may be.

sync data to server android

I'm new to android sync so I really need ideas to get started. Actually my app's requirement is like this: My app needs to connect to my database online. But my android app can be used offline meaning, the user can add records to a local db, say sqlite. And then when the user connects to the Internet, the app should automatically connect to the server and add the record the user added when he is not online. Can you give me some considerations and ideas on how to do this? I really need your help guys. Thanks.
I will recommend you to go for Sync Adapter. See these links
AbstractThreadedSyncAdapter and Creating Sync Adapter.
I have used them long time ago. I will say that it is the best approach for syncing data between device and server. Usually, email apps use these sync adapters.
Sample is also given there. Download it if you want to go deep inside of "HOW".
Thank You!
You need to run background service like android alarm manager. You need to check that device is connected via internet or not. if device is connected via internet then sync the data to server.
Check this like to the way of data sync
How to sync SQLite database on Android phone with MySQL database on server?
Thanks

Android c2dm push notifications after app reinstall

I have the following question:
I've successfully implemented C2DM in my application. I'm registering to both google c2dm cloud and a custom server that "creates" notification contents. Everything is working fine.
My question is : what happens when i uninstall my app and then reinstall it on the same device? I've noticed that C2DM is sending me back the same app_key, so apparently there's no way to determine my app installation status change. And i keep on receiving old push notification (they're customized by user preferences in the app).
I won't be able to test with a google play published app until final release, so i would like to know if there's a chance that google itself could notify c2dm that the app was uninstalled on my device and force it to change my app_id at next restart.
Thanks in advance
Stefano
From what I understand in C2DM, you shouldn't depend on Google's registration ID by itself. They "promise" nothing - you might even get a new registration ID without a clear reason (might be their own vrsion upgrades, etc.).
If you want to follow installation - you should do it with your own server - create a unique identifier whenever the app asks for registration, and use it and not the Google's registration ID.
Regarding to Google Play - couldn't find a difference between published app and unpublished one - the behavior seems to be the same.
Hope this helps somehow.
Shushu

Categories