Android GCM not letting me sleep - java

I've made two apps to work with GCM notification in one I've done that using my own php server to store reg ids and then send notification to app users using GCM . and i've coded it myself in java also to receive that notification successfully i've done that using documentation of Google Cloud Messaging
So in 1st app which i coded manually i'm getting all notifications as i was expecting then there was problem that screen was not getting on while i receiver notifications . I've accomplished that also using WAKE_LOCK.
Even my app not present in ram of device which we mostly now a days we use hold on menu button and clear ram.
but still i get notifications.
Ok so here 1st app story ends.
Now let's go towards second app
I've made that using https://onesignal.com SDK
That was so amazing and easy and i've done it earlier.
just this line of code did all.
OneSignal.startInit(this).init();
So every thing is working and all is done . But problem is that when this app is cleared from ram like i defined above i don't get even single notification then to be sure more i check my cell phone running app section and i was not able to find my 1st and 2nd app there but i found google play services running 5 services when i tapped on that i got that gcm is also running . So i'm not getting that what can be the issue with 2nd app ? what i should do to make it like 1st one with this sdk
I'm really very worried and any help will be appreciated thanks.

Just to confirm in your 2nd app with OneSignal you are sending a new notification from OneSignal each time? If you're replaying a GCM payload the OneSignal SDK will omit processing it to prevent duplicates.
Which device and Android version are you seeing this issue on? Test on multiple OS versions if possible.
Also check the logcat when you kill your app and when you send a notification from OneSignal. It sounds like your app could be getting put into a "Force Stopped" state. See the following gist for an example of the logcat messages that show from this.
https://gist.github.com/jkasten2/fb83b1df754cf26df378
Thanks.

Related

Update database on server when app is being uninstalled

I know there might be many questions like my question. But It is different. Actually, I am making a static chart that will show how many devices currently having my Android app installed and how many devices have uninstalled it.
For this, I am creating a uniqueID when the app is installed on a device and saving uniqueID along with FCM token to SQL database on the server.
To Create uniqueID:
uniqueID = UUID.randomUUID().toString()
Now, while I am saving every device with a token and uniqueID to the database. Of course, the device will be considered to have active app installation even when uninstalled the app.
So, I want to add a field in the database as inactive against the device that has uninstalled the app. To achieve this, I am thinking to send a request to the database and update the information when the app uninstallation is triggered.
Is this possible? And if yes, then can anyone please tell me how. Or are there any other method to achieve this. Thanks in advance.
Yes it it possible. You can send a push notification to your app to all your active users everyday from your backend side, and on your Android side, call an API on your server to confirm that you exist. If a client does not confirm his existence in a period of time (like 3 days), you know they have uninstalled the app. This is what Adjust and other statistics do for uninstall statistics.
You can't easily run your own code when an app is uninstalled. It is possible to run code in another app, but that requires that you get the user to install both apps.
In addition to the approach Adib described, you can consider using Google Analytics for Firebase to detect uninstalls of your app by Android users. As shown in the answer to this question, Firebase automatically tracks uninstalls in that case.
Maybe you want to use Firebase Analytics and the event app_remove. Mark it as a conversion and use Functions to remove the user from your Firebase Project(if anonymous) and/or any other data associated with the user(Storage, Database, Firestore, etc.) or anything else you might want to do upon user removal of the app.

Permanent services on android oreo

Android 8's battery consumption improvements are nice to the user but I am a bit afraid if my service will work as expected.
First of all: Thank you for any suggestions but I cannot just schedule my service. I want to make a OK Google-like keyword listener running in the background all the time. It will be based on the open source pocketsphinx-android library. I know that this will consume much battery power and I will inform the user about this.
Can we create a permanent background service on android 8+ ? I need to target android 8 in gradle because I was expecting some bugs with older targets. I also don't want to annoy a user with a foreground service which permanently shows a notification in the status bar.
[https://developer.android.com/about/versions/oreo/background.html] - Is there really no way of making permanent background services for my use-case (but preferably for all use-cases) possible?
Unfortunately, it's not possible to use a background service and don't show a foreground notification on Android 8.0 and higher.
The only one way that it might work is if you stick your app to Google APIs such as Voice Actions API.
As far as I know there is no a good work around and most apps like WhatsApp are still targetting Android API 24.
For what is worth, I am sharing me experience on that:
It's partially possible to use a background service and not showing a foreground notification on Android 8.0 just made some experiments and ended up with this:
Just create a notification channel with IMPORTANCE_NONE, and the notification will still exist, but will not be displayed in status bar.
Code excerpt:
NotificationChannel channelService = new NotificationChannel(
YOUR_SERVICE_CHANNEL_ID,
YOUR_CHANNEL_HUMAN_READABLE_NAME,
NotificationManager.IMPORTANCE_NONE);
channelService.setSound(null, null); // let's be quiet : no sound
channelService.setLockscreenVisibility(Notification.VISIBILITY_SECRET); // not on lock screen
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
// changes needs to uninstall app or clean app data, or rename channel id!
notificationManager.createNotificationChannel(channelService));
This way, the notification will not be displayed when your app is running in foreground.
Not a perfect solution:
When your app goes in background (i.e., you open another app), the "Android system" app displays a notification about "(your) app being running in the background".
So, this is not great, but, from my point of view, it's a bit better than before.

Android FCM Push Notification Not Working When App is being Killed or Swipe Out from Recent Apps on One plus 3t Mobile

We are Developing an android app to receiveing a push notification from fcm we throughly tested the app in different mobiles all are working fine except oneplus 3t mobile. It Does not receive notification when app is being killed or swipe out from recent apps.It receives notification when app is in foreground or open.
We search lot of thing from internet lot of site says change the notification payload to data we are also change that it does not working in oneplus 3t mobile. And also give the android xml attribute
android:stopwithTask="false"
Nothing worked. Please give some solutions regarding this issue. In my point of view firebase messaging services also stopped when app is killed.
Please check in mobile device is there any protected app feature or battery saver which stops the working of app in background. If allow the app to run in background from setting it will sort out your problem. I'm having honor 5x device which was having the same issue. To run the app in background I've added it in protected app list.

Android Push Notifications on Android Device that can not install Google Play Services

I have a Android Device that does not have Google Play Services on it and can not because it is not a certified device.
I am looking for a way to send Push Notifications to this device to wake it up and process an incoming message.
We have the ability to customize the Android BSP (ASOP) if there is any possible way to create our own custom Push Notification server to accomplish this?
Yes there is. Just the other day I had the same question. My scenario involved real time notifications though. Everything is updated in real time . and the idea of using web sockets came to me. And luckily I knew socket.io , luckily android had a native build with gradle. Consider researching into this concept.
Right off the bat. Features like back off time checks, back pressure and timeouts.

Notifications when the app is turned off

I wonder if it is possible to have notifications show up even if the app is turned off.
say for example I have an app and I set some kind of notification for 13.00 the next day and then turn the app off or restart my phone or something.
Is it possible to still get a notification in the notification bar with some text that starts the app or do the app need to run in the background to be able to use notifications?
if it is possible, what is the best way to do this? (get a notification at a certain time that starts the app) and if not, how do you recommend doing notifications?
The type of notifcations I want to do are reminder notifications.
thanks for all help!
A combination of AlarmManager and Service will help you to perform the task you are looking for, I had performed this thing.Check out the android tutorials for it.
What you're looking for is a background service. See this Android Services tutorial.
In the background service, your app should check periodically and when necessary, create and issue new notifications. See this Android Notifications tutorial.
The background service can be set to automatically start when the phone is restarted, and to re-issue any uncleared notification again.
Many apps such as Gmail already do this. Although you must be careful in resource usage or Android might kill your service.

Categories

Resources