Fast connection to Google Services ( in order to receive push notifications) - java

I'm facing an issue on my phone under Android Jelly Bean 4.2.1 (but not on my tablet with Android KitKat 4.4.2).
What I have is an instant push notifications system which works perfectly, as long as my phone is connected to Google Services (blue icon in the notification bar on Jelly Bean). I'm working with Parse.
The problem is that it takes about 2 minutes to get a connection and that is way too long.
I've seen a lot of threads about the Heartbeat rate and tried to add those lines in my code:
context.sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
context.sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));
but it did nothing and I don't think that it is really my problem here.
In addition, I found by dialing *#*#426#*#* that it was possible to get a connection in less than 5 seconds by clicking the "Connect" button in the Google Play Services monitor.
My question is: How can I have a fast connection with Google Services (blue icon) in order to receive instant push notifications and is this still a problem on Android KitKat and Lollipop?
I Hope you will be able to help me.

Related

Nearby Connection : Discovery issues on Android 10

For one of my project I work with Nearby Connection API with P2P_STAR strategy and I experience issue on discovery with Android 10.
I have tested with Huawei devices that resulted in no connection at all with host and on a freshly updated Xiaomi MI 9t who success to connect but disconnect few seconds after with no exceptions...
Before the update it work well on the Xiaomi.
Furthermore, my app work very well on my android 8 or 9 devices.
I tried to add ACCESS_FINE_LOCATION permission and update Google play services without success...
Our project repository : https://github.com/hbollon/Urbalog
All Nearby stuff is in NetworkHelper class and permissions list is in the constant REQUIRED_PERMISSIONS inside it.
Someone would have any idea?
Thanks in advance
So I have found the issue, on my android 10 devices I haven't activate location and Nearby seems unable to activate it itself...
I never notice that before Android 10 update so is it os related or have I always activated it before? I don't know ^^
However, on the ConnectionsStatusCodes documentation, MISSING_SETTING_LOCATION_MUST_BE_ON status code is marked as deprecated ( https://developers.google.com/android/reference/com/google/android/gms/nearby/connection/ConnectionsStatusCodes ).
So I imagine this is no longer a possible case no?

bind service stops after 1 or 2 mins when phone is locked in some devices like oppo, one plus device

IN bound service when I lock the device after the 70- 80 seconds service stops I am testing on realme 3 pro and one plus 5 both having API 9 PIE. How to keep service running until the app is in recent activity. Even foreground services are also stopped. Thanks in advance.
Realme, Oneplus, Samsung, Xiaomi, Huawei and a few other manufacturers have their own layer of "Battery Saver" or "Security" that kills or restricts background running apps in order to improve security/battery backup, unless user white-lists your app in the relevant device settings.
What i found out about Xiaomi is that they white-list well known apps like Facebook, Whatsapp, etc. But you cannot request Xiaomi to white-list your app.
These manufacturer apps simply terminate your app process. So your app should behave in such a way that termination at any moment should not create inconsistent state.
Also, you can always show a popup to user after installation asking him/her to go and white-list your app in battery saver. In Xiaomi, the user will need to select 'Do not restrict background activity' and also enable 'Auto Start' for your app. As far as i know, there is no other solution.
Conclusion: Visit https://dontkillmyapp.com and see how the apps are whitelisted for your OEM. Once whitelisted, it will work as expected.
But out there in real world, it will get killed and users won't manually whitelist it.
Custom Roms have it's own security apps and it close the app service when u remove it from recent or after few minutes.
To keep running your app in background you have to enable autoStart from settings
Refer this : How to fix the issue that the activity is killed automatically after some minutes in newly version as like vivo and oppo
Facing same issue from long time, Try to add FCM in your application and start service from it directly or else set alarm and startservice.
In some cases above solution work. i have added above solution in 4 project but succeed in only 1.
Issues which I have found while overcoming problem with firebase.
Firebase Notification coming to app but Background service not starting
Firebase Notification Not coming to application
Firebase Notification coming and service starting with Broadcast Receiver (Sometimes
service not starting directly from onMessageReceived() method of Firebase so i
decided to set broadcast Receiver ) but sometime its stop working.
Issue which I have found without implementing Firebase
If we set background service to run after every 5 mins than for 1-2 hours its
running on 5 mins interval but after 2 hours time gap increased and service runs on
15 mins of interval and in some devices its run on 20-30 mins of interval(i found
this in right time because phone may goes in ideal mode).
As mention in your question, sometimes any of above implementation doesn't work.
Tip : What I found in system alarm log ?
I have set alarm for 2019-08-08
11:07:00 which not fired and current time is 2019-08-08 11:10:00 but its showing in
pending in system alarm log.
You can check system all Alarm set by your applications
D:\SDK\platform-tools>adb shell dumpsys alarm

Android 8.x notifications : how to avoid the fade in/fade out of the notifications over my app when my app is open ?

When the user performs some specific actions in my app (while my app is open and visible full screen by the user), it creates a notification with some useful information.
Nevertheless, I want this notification to be visible only in the notification tray. I don't want that it fades in/out from the top of the screen over my app while the user is using the app (like it worked before on Android lower than 8).
I have got this problem on Android 8 with the new kind of notifications using the notification channel.
So, how to avoid the fade in/fade out of the notifications (created by my app) over my app when my app is open ?
Thanks.
I reduced the importance of the notification channel to IMPORTANCE_DEFAULT.
But, I noticed that to test properly the changes in the channel parameters, I have to uninstall/install the app and also potentially to change temporarly the name of the channel ID.
To avoid some strange bugs on the notifications (e.g. : notification showing with fading in/out from top even with IMPORTANCE_DEFAULT, sound on the notif even with IMPORTANCE_DEFAULT, etc...) I had change my project target from 26 to 27.
Hope this helps.

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

Bluetooth Android issue

I am running a multi thread application on android and adobe air, in native android 2 bluetooth sockets are set up and a couple of server threads for the air app to communicate with the bluetooth sockets of native android. It's basically socket programming and it all works on one device I used to programme it.
The device i used to develop this app was slow, i therefore got myself another tablet to test (android vega) and it is very fast at communicating my bluetooth data as it has 2.1edr version.
The problem is with the Advent Vega tablet the bluetooth streams just disconnect for no apparent reason intermittently and in the adb log window i just get trying to connect to device all of a sudden when the disconnect occurs, i have no mention of the crash anywhere in the log, this happens to both bluetooth connected threads at the same time so it must be something to do with the bluetooth radio im suspecting. The other tablet device runs the app fine but slower (no disconnects). I have even installed a custom 3.0 rom on the vega to see if it was a os problem but the disconnect problem persisted on 3.0 as well.
Due to the fact there is no mention of this in the adb log i am just basically staring at a screen with no idea of why it disconnects for 2 days now!! The only way to get the app to run again after this disconnection occurs is to restart the bluetooth on the device but this disconnect occurs again eventually when next run. It seems to improve the amount of time it stays alive tansferring data when the app is first run afater a re boot.
I have gone through all code of the run() and stopping() of each thread and it seems to exit gracefully, i close the bluetooth sockets only, it seems from research no need to close the bluetooth input and output but i have also tried that approach to closing.
Can anyone offer suggestions as to why both bluetooth read/write loops would just stop all of a sudden and disconnect? Seemingly effecting the adb log as well as it just says trying to connect...
Or any suggestions as to how to better debug when this occurs?
Or even what somebody else would do in this situation.
Hope someone can help, i have a great phone remote app for the android tablet owner community and it hinges on this final issue which i have been stuck on for 2 days.
I had problems with disconnects, and implemented a keepalive by sending a ping request and a ping ack.
This worked fine for me...

Categories