I'm building a security system for my office, which can be controlled via an android app. The app also should notify the user when an alarm is triggered by the security system. Therefore i'm using FCM push notications.
But how can i play a notification sound at full volume, even when the phone is in no-disturb or silence mode?
There is an app i used before, called "pushover", which lets our employees receive a push notification when the alarm has been triggered. They have a setting in their app "play high-priority notification sounds through alarm channel", which does that pretty well. But what does the "alarm channel" mean and how can i send notifications through it?
THere's different streams of audio in Android. One of those is the alarm stream. That setting would use the ALARM channel for this sound. This will not go through silence mode- the alarm channel has a separate volume control from media, but is still set to 0 if all sounds are off.
And you wouldn't do this through a notification. You'd do it through Java code in your app when the notification is received. But there is no way to force a sound if the user is in silent mode.
Related
What I have studied on stackoverflow and Android documentation.
Finally I've concluded this:
There is no way to create a background service for continuous tasks. If I really want a service I should start a foreground service and user continuously sees a persistent notification "App is running". There is no way to hide this notification. It is intentionally added by Google.
Yes there are other options like WorkManager and JobScheduler but they do work periodically not continuously.
What I do want is to build an instant messaging app which continuously connects to the server using xmpp or sockets. But it requires a continuous connection but I don’t want to use a foreground service because it shows an irritating notification to the user "App is running".
Question 1: How does Whatsapp and other instant messaging app continuously connect to the server but not show a persistent notification ? How do they achieve this ?
Question 2: If Whatsapp use FCM for notifications then it will also work in those mobile which do not have playservices installed, so how does Whatsapp notification mechanism works ?
Starting with Android 6.0 (API level 23), Android introduces two power-saving features that extend battery life for users: DOZE and APP STANDBY. These two features enforce many restrictions on your background processing while the phone is in Doze mode. You should read about Doze and app standby in the following link
https://developer.android.com/training/monitoring-device-state/doze-standby
Now, about your use case is that you want to receive the messages and incoming calls even when the app is not running. For this use case, Android announced High Priority FCM messages in GoogleIO2016. They are high priority Push message which grant the application temporary wakelock and network access, independent of Device's Doze state or if the app happens to be in the app standby. This allows the application to react to the message and notify the user in whatever way it wants about the instant message or incoming call.
I don't know exactly how WhatsApp does that unless I look at their code but you can handle your use case using FCM High Priority Messages.
For more about your use case, follow the below link ofGoogleIO2016 Video from 08:30m to 10:30m
https://www.youtube.com/watch?v=VC2Hlb22mZM&t=505s
and read about this use case on the first link in this answer.
I have simple app for show pageView with text, I want to notify user at specific time every day to open my app at specific page.
So I test my App by Marshmallow device, I am using alarmManager for this task, but once I close App from main screen notification stop showing.
I used Broadcast Receiver with remote process android:process=":remote" but Alarm not work also I used service also it killed with closing App.
So what is right sequence to achieve this job?
You don't need to use Service. AlarmManager and a BroadcastReceiver to restart alarm service on device boot.
Check this example:
http://stacktips.com/tutorials/android/repeat-alarm-example-in-android
When I was making alarm clock app for me Service with WAKE_LOCK was waking up the phone when it was blocked or the app was killed by user.
This class(with some notification displayed) is preventing app from being killed :
https://github.com/mrkostua/SmartAlarm/blob/master/app/src/main/java/com/mrkostua/mathalarm/alarms/mathAlarm/services/WakeLockService.kt
So after scheduled intent can be send to BroadcastReceiver.
I am working on an Android project that has a part which dose this:
1) the user enter a data from a data field and save it in a text file
2) the app should send notification even if the application is killed by the os, at that date, the one wrote by the user.
For example:
I write 31.01.2015
The app will notify my only on 31.01.2015 even if i don't open that app anymore.
The question is how do i have to do this?
Thanks!
It sounds like you want a notification to be posted to the notification bar.
If so I advise using an alarm.
However, chances are if this is days in the future, the phone may be shut off. So you should store when the alarm should go off, create a Broadcast receiver for the on boot complete event (this requires a permission), and re-setup the alarm when the boot is complete.
This should allow the notification to appear, independent of the apps life-cycle, as long as the app is not uninstalled.
Note: You will have to calculate the milliseconds between the date for the alarm, and the current time. Calendar should help.
In my android application i am using android push notification everything works fine until the user forces the application close(It happens always nowadays especially with the task monitoring application available in the play store).No more notifications are visible or possible.After some googling i found that From android 3.1, if the user force closes an app, it will stop to be notified of any broadcast until the user does not start your the again.
Is there any solution to prevent the broadcast receiver killing or any other possible (like making a Que of messages that aren't received by the device and send them later)?
if the user force closes an app, it will stop to be notified of any broadcast until the user does not start your the again.
sorry, that's not true. for sure.
I think you are confusing with something else: from android 3.x - broadcast receivers would never react to a broadcast until the app is launched for the first time.
if you implemented properly your GCM client side - it should work even if user force close the application. that's because the operating system waking up your application if it has the right broadcast intent filter and receiver, what mean that your application don't have to be running in order to receive this broadcast.
No more notifications are visible or possible
If your indication that the GCM not received is the fact that you don't see any Notification, then it's not necessarily true - there is no direct connection between GCM message to the system bar notifications. that's true that usually you'll show notification when push received, but it's deferentially not must.
what I'm saying basically - maybe you have a bug that takes affect after the user force close your app that causing the notifications not to be shown.
I am working on Push Notifications in Android. Now the issue is that I want to keep running my Push Notifications on the back ground as soon as the app start because I have no idea when the server will push the data to the devices.
The main requirement is that our corporate app is having more than 10 activities and based on the notification received, I have to bring the related activity on the foreground so that user can preform action on that or do some silent action in the background regardless the activity is in foreground.
Can somebody suggest how can I implement this type of requirement. Do I need to do it in a Service.
Thanks
An Android application on an Android device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives, as long as the application is set up with the proper broadcast receiver and permissions.
take look at this;
http://developer.android.com/guide/google/gcm/gcm.html
when message received from gcm server
onMessage(Context context, Intent intent): method of GCMIntentService gets fire,
so you write your code there
take sample example from here
https://github.com/ketanpatel25/GCM-Demo/tree/master/gcm
What you're trying to do defeats the purpose of push notifications. In push notifications, the server sends the message through Google APIs. These APIs then send a broadcast message to your app, which you listen for. Continuously keeping the app open in the background and asking the server for new messages is called polling.
Read up on the GCM documentation. Whenever you receive a message, Android will ca the onMessage(); method of your GCMIntentService.