My implementation of the GCM works normally when the app is in the background or shut down, as is should be.
But when the "Background data" (in the "Account and Sync" setting of the device) is disabled, I do not receive GCM notifications anymore.
I am not 100% sure if this is the sole reason is the "Background data" setting, but based on our experiment, it seems like the "Background data" is the variable for whether the app receives the GCM or not.
My First Question:
Is this an expected behavior, or are we doing something fundamentally wrong?
My Second Question:
I have heard from a fellow programmer that some people create a new Service to live in the background and listen to incoming GCMs.
I am still trying to figure out the logic behind this, but does it sound like a viable option?
Sorry for being vague in my question.
I am still struggling with the design of the solution to this problem so...
In the same way that Google Play requires background data enabled Google Play, I guess GCM do so.
When you try to acces to GCM and there is no account registered on the phone an error ACCOUNT_MISSING is returned by the GCM services, and when you detect it you should redirect to the ACCOUNT_SETTINGS so users could add a google mail.
After that, you will have to detect if that background data is enabled using the ConnectivityManager function getBackgroundDataSetting().
Take care of it, it was deprecated on >= 14 API, you will have to use getActiveNetworkInfo() instead to see if apperas as disconnected because the user has disabled background data.
Other way if you see the last link is registering a listener with the filter ACTION_BACKGROUND_DATA_SETTING_CHANGED (but deprecated on API 16).
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
According to the android manual :
Background data controls whether applications and services can
transmit data when you are not working with them directly
It doesn't explicitly say that background data is GCM but there are lots of evidence and a bunch of threads that all say :
GCM messages are not delivered when background data is disabled
you can easily test it yourself, disable background data, go to the web version of play store install an app. You will only receive it when you re enable the background data. If not even google can make it, then likely you wont be able either.
If you still think you saw applications receiving GCM messages when background data is disabled it can be because of :
In newer android phones you can enable background data per application, probably it was enabled for an another app
Probably what you saw was not a GCM notification, but the application falls back to polling the server when GCM is not available
If you are still not convinced then set up you phone to use a proxy server like burp suite on your machine and you will be able to see what other apps are doing on the network.
Related
I am creating a native social app which includes features such as Direct Messages, Voice and Video Calls etc and I have been trying to find a way to be able to receive data payloads from Firebase Cloud Messaging containing values such that I create a custom notification based on the type values from the data payload eg for VOIP calls I’d like to set a remoteInput action to see if a person declines or accepts a call or for direct messages add a remoteInput action for a quick reply and so far I haven’t had any luck especially with background services not being allowed anymore ever since the release of Android 8.1. So I would like to know if there’s a workaround I’ve been missing or if it’s even possible and if it is how do these popular apps do it. Thank you in advance.
Its same as your mentioned, once after the release of 8.1 apps are now more strict in regarding the background running process. There are actually two insights I had received while developed some projects. 1) More the app is used by the user, the app is sort of whitelisted and can receive more notifications, i.e., the system actually tracks the frequency of app usage. 2) You have the possibility to ignore your app from battery optimization process hence more chance of background process to run.
I have a few apps which are dependent from server side. From there are getting they data.
The server side needed development anyhow. Server code hosting is done in our side. The client-server communication, structure is already up.
In this state we need to implement a push notification:
If there are new data on the server than it should be visible at user somehow.
The "standard", recommended way now is to use Google Cloud Messaging System.
I have a few concerns about it:
Requires client and server side coding and bind they technology in our code. And not this is the biggest:
Is changing relative often the technology: deprecation, and need to change our code. This is the biggest. Previous of this was something other and before that something other. In 4-5 years 3 changes is to much.
I am thinking to implement like this:
I will write a broadcast receiver listening when the user got internet connection.
On Internet connection it will check the server to see if it has something new or not.
If is does than it will show a notification and job is done. If the user clicks the notification it will start the app and download the playload.
I will use an alarm schedule, to check the server again after 1 or 15 min or 4 hours, whatever. There it will be no service running in background, just receivers!
The register - unregister functionality should be done in app.
Communications to server in plus:
registerMyDevice(IMEI)-or username+password
unregisterMyDevice(IMEI)
isSomethingNewData()
When the client comes to server it will send his IMEI anyhow to identify, so the server will know for who need to send push.
Anybody can take Google proposed solution and prove it is better in this case than our in-house solution?
The main problem with that solution is that you'll add one more background process that shortens the battery life. Imagine what would happen if many app developers choose to implement your solution. A user that installs several such applications will have their battery emptied quickly. With GCM, one connection is maintained with one server, and that connection serves all applications on the device.
I believe integration with GCM is simpler than developing a push solution by yourself. The API changes always come with improvements (original GCM allowed multiple senders while C2DM didn't; the new GCM gives you user notifications and device to cloud messaging), but even if you don't choose to work with them, the old APIs still work (even if they are deprecated).
Prior to posting this query here, I have gone through a similar requirement by a user in the post here
Based on research, what I understand is, push notification concept can be used to notify the application of any changes happening in the server, if and only if, the server control rests with us.
I have made an application which would display the data from a mobile website. Is there a way out by which I can notify the handset user of any change happening in the server, such that the user gets an alert in his handset, so that he can open the application and see what is the new addition/change that has occurred in the website, when I have no control over the server? Pardon me , if I sound totally dumb with this question. Had such a requirement and was curious to know the way out, if any.
This way you should build your own web service which will poll other service for changing and then push alert to android device via Google Cloud Messaging for Android (GCM).
But you also can poll this service with your own application in background service. This method is very bad because of battery drain and network connection using, but this is no need for 3rd party services
try noczone.com, they have custom notification service with an easy to use PHP sdk
https://noczone.com/?page=custom_alerts_sdk
i use it to let me know whenever i receive a support ticket or any new registrations.
and you will need to have their app installed to receive notifications on it
https://play.google.com/store/apps/details?id=com.wr.noc
I always thought WhatsApp uses c2dm for message delivery. But when I see running apps MessageService is always running. You don't need a service to be run to receive c2dm.
Why keep the service running all the time?
Facebook is even more strange they have 3 services running. One of them is for uploads. Did they start stealing my photos?
Like cached background proccess say - this is an old application proccess that is being kept for better speed in case it is needed again. I suppose, same thing happening with services
WhatsApp uses something like XMPP
WhatsApp uses a customized version of the open standard Extensible Messaging and Presence Protocol (XMPP).
See: http://en.wikipedia.org/wiki/WhatsApp
I'm using GCM myself for a chat application for Android. It's still not working properly if the device is idle for a long time.
I am creating a app in android 4.0.3 i.e ICS version, which connects to the server when client gets login into the app.I am trying to get status of an client when he gets online or offline through server & seen onto the app screen.I am unable to proceed. Can anyone say me:
Is it possible to get the status of an user through server?
1-- How to proceed for first step...?
2-- How should I get a response from the server that the client is connected & viewed to other client example - when we login into skype our status shows available with green radio button, In same way how can I get it.?
It ll be very help full, If anybody guide me.
Many Thanks..
I'm assuming you're trying to develop a chat app ?
If this is the case, try using an XMPP library. XMPP is widely used for chat apps, including Facebook chat (and Google talk I think) and there are plenty of open source libraries available.
Otherwise, if you only want real-time notifications as a part of a bigger picture, try using push notifications. Google supports Cloud to Device Messaging (C2DM) for android. It allows to have push notifications to a specific device without you having to deal with persistent connections, battery and CPU use .etc.
C2DM approach comes down to this. When a client connects to your server, get a list of his friends and their 'C2DM IDs' and fire a C2DM push to their devices. This push is delivered to your app, and you can respond to it by firing a notification, or update UI .etc. (Your app doesn't necessarily have to be running. Push notification is delivered via a specific broadcast, and your app can register a receiver for it to wake up.)
Keep in mind that there is a quota for C2DM messages per device, per app and also a limit for the payload per message. So you're not supposed to send massive files via this. Just a notification to your app, so it can call your server and get an updated list, instead of polling.
You can get more info on C2DM and code samples here. https://developers.google.com/android/c2dm/
Hope this helps.
You may have moved on, but I'm posting for anyone who would run into this one in the future.
Firebase is a good solution to use in this scenario, if the app is always running when you want communication to happen. (It will not wake up your app as C2DM/CDM does, unless you have a service running all the time and still wouldn't wake up if the device is asleep... AFAIK)
It may be useful for some scenarios, but may be not for a chat app as you want the device to wake up when a message arrives.
Note that they have limitations on the free subscription though.