Manage Push notifications on Android: how to enable and disable
Android is a platform, very rich in settings that allow you to configure the work of the smartphone exactly as it is necessary to the user. However, it becomes a repulsive factor for those who are not too close familiar with the features of the operation of mobile operating systems. Still, because it is always easier to follow the appointed scenario of use and not be able to influence anything, as it happens on iOS. But this approach is good only at first, because it is quite naturally time to start to want something more, especially since it is sometimes vital.
Notifications do not come? Perhaps this way will help
Push Notifications in Android. Rake, crutches and bicycles
To write this article, I was pushed by a task that was put in front of me in one of the work projects: to implement push notifications in the application. It seemed that everything was simple: it looks for documentation, examples and ahead. In addition, experience with notifications has already been. But it was not there the service, in which the Android application is implemented, presents quite stringent requirements for the work of push notifications. It is necessary within 30-60 seconds to notify the user about some action. During successful alert from the user device, a request for a server with the appropriate status is sent. From the documentation it is known that the GCM service (Google Cloud Messaging) does not guarantee the delivery of push-notifications to the device, so as a backdoor option, when you violate these time frames, our service notifies the user using SMS messages. Since the cost of SMS messages is significantly higher than push notifications, it is necessary to minimize the SMS stream of messages to client devices.
Having shifted the documentation and fastening the push notice, we sent to several clients to the first assembly of the application for test and began to wait. The results were approximately following:
- With an active Wi-Fi connection, everything works perfectly: notifications are delivered, customers are happy.
- With an active mobile Internet, the most fun.
- Included power saving mode (for example, Stamina on Sony devices) affects the work of Push notifications;
- The user must have a minimum of 1 active Google Account on the device;
- It is necessary to make sure that the device “Google Play” application is installed on the device;
- Check if notifications are disabled for the application (check mark on the application page in the phone settings);
- Check if the work of the background mode is not limited to the application (setting is located in the “Data Use” menu); It is indicated that notifications are sent only by certain ports, so the router, firewall and antivirus settings also should be taken into account.
At this stage, the article written by the guys from it was very detailed described the finends of the implementation of GCM on the client side, as well as moments, in connection with which Push notifications in mobile networks refuse to work. Ultimately, it was decided to keep its connection with the server in a bundle with GCM.
Before proceeding with the solution, it costs to distinguish several very important moments that allow you to narrow the circle of potentially “non-working” devices:
The used Android developer will say that task solutions at least 2: Use Service or Alarmmanager. We tried both options. Consider the first of them.
In order to create an unnecessary service system that will constantly hang in the background and fulfill our task, we used the method:
- Notificationid. some unique notification identifier, which will be displayed in the status bar and in a traveling blind;
- Notification. notification itself.
Realizing this approach, we sent an assembly to the test. According to the results, it turned out that the system still unloads the service, and by logs we saw, as significant temporary breaks occurred when requesting data in the background from our server. Therefore, the second option has begun. AlarmManager.
Alarmmanager is a class that provides work with, roughly speaking, “alarm clock”. It allows you to specify the time by the achievement of which the system will send a broadcast notification that will ensure that our application will awaken and give it the opportunity to perform the necessary actions. There are some restrictions in this method, and they must be processed:
which allows you to install repeating with some interval “alarm clock”. Printing this method, began to test, and the tests showed the opposite. “alarm clock” did not repeat. Began to understand what’s the matter, I looked at the documentation. And it was there that they found the answer to the question. starting with the 19 API LVL (Kitkat) absolutely all “alarms” in the system became one-time. Conclusion. always read the documentation.
These rakes were not a reason for the disorder, because the solution of the task is quite simple. to run a unite “alarm clock” and after responding to reinstall it. When implementing this approach, we came across the following rake. it turned out that for different levels of the API, it is necessary to install alarm clocks in different ways, while nothing has been said in the documentation. But this problem was solved quite simply. by the “Tyka” and “Google” method. Below is an example code that allows you to properly install “alarms”:
I want to pay attention to the ALARMANAGER flag.RTC_WAKEUP. it is using it that the system will allow our application to “wake up” with an inactive screen when the device is in a locked state.
This approach with “alarms” gave us the desired result. the application in the background correctly polls the server for new data. Now we are improving the algorithm. At the moment we sell and test the following optimization, which will allow you to narrow the range of devices and thereby reduce the load on the server:
- The message sent by the GCM to the device contains some unique ID;
- After receiving the data of the GET as a query in the background, check whether there is already a record with such an ID on the device;
- If there is no such data on such data, we remember this ID and its receipt time T1;
- We are waiting for Push with the same ID, upon receipt I remember T2 time and check the difference between T2 and T1;
- If the difference is more than some time criterion (values), then the device has a problem with the delivery of notifications and for the correct operation of the service it is necessary to constantly request data in the background from the server (Criterion I advise you to choose from the task being solved. In our case, a criterion was chosen equal to 5 minutes);
- This difference should be calculated several times, for example, 5-10 times, only after that it is concluded that the device really contains a problem to obtain PUSH notifications (thus eliminated the situation of the banal disconnection, timaout, etc.);
- It is necessary to drive this algorithm periodically (for example, once a week, or after updating OS on the device).
System Disabling Notifications
The ability to configure alerts began to be embedded from Android Jelly Bean devices, you can either completely disable notifications for each individual application, or include all. Android 6 has already appeared more subtle configuration, allowing you to adjust the frequency, sound and other parameters.
The users of the last versions are enough to press and hold on the annoying pop-up notification until it is possible to manage it.
Literally in two actions, you can translate all the alerts from the application in a silent mode or completely block. If this is not enough, you should go to “Other Settings”.
Turning off the automatic mode by pressing the letter “A”, you can adjust the level of importance by moving the slider. Depending on its position, it changes:
Additional options are available below, allowing you to determine which information will be available on the locked screen. in this way you can enable the display of all data, with the exception of personal (for example, messages) or block notifications of this nature and not to demonstrate them without unlocking the device.
Also notifications of this application can be transferred to the category “Important”, and in this case they will be allowed to know even in the “Do not disturb” mode. By setting a frequency limit, you will not hear more than one alert for a specified period of time (from 10 seconds to 30 minutes).
How to go to the Notification section?
Go to the same menu to configure the notifications for each application, you can and other.
Go to the phone settings. The gear icon is located in the general menu or on the right side of the “curtains”.
Under the heading “Device”, click on the “Application”. Choosing a suitable utility in the list, click on the “Notifications” section.
In versions preceding Android 6, there is no such partition, you can deliver or remove the check mark on the “Enable Notifications” item in the settings of the selected application.
If this option is missing on your phone, you should update the shell or contact the settings of the application itself.
We change the sounds of notifications
If you are used to and live without any audio notifications, there is an easy way to optimize the way they are received. By setting a certain sound for important categories of notifications, you can instantly understand when something requires your attention, and when the new notice can be safely and without consequences ignore.
This time we need to come again in the category notifications, as described in the first paragraph and click on the item “Sound”. Now choose any ringtone that you have saved in advance or create your own by clicking on the plus icon at the end of the list with ringtones. Over time, you will learn to determine the types of notifications one by one sound, and if you like this concept, you can apply the same settings for incoming calls in the “Contacts” Appendix.
Belongs to Meta Platforms, recognized as an extremist organization, its activities are prohibited in Russia
How to enable the application in the background
How to prohibit applications unload from memory
Swipe down the open application window will secure him in RAM forever
- Disable the autofilling of the launch and turn on the “Autostask” parameters, “indirect launch” and “work in the background”.
- Start the desired application and go to the multitasking menu, find it in the list and swap over it. it will fix it in memory.
After that, the application or application depending on how many of them will stop unloaded from memory both with increased battery power consumption and with a mass closure of all open programs in the multitasking menu. This will solve the problem with notifications that may not come due to the fact that the system does not have the ability to provide the background work of software, and you will constantly know all the events that first risked to miss. Therefore, first of all, it is worth moving on manual management of customers of social networks, messengers and mail applications, notifications from which are extremely important.
General information about Push Notification technology
Push notifications. this is a way to distribute content (system messages) when notifications are sent from the server to the client at the server initiative based on certain parameters. In contrast to the Customer-Server reference scheme (Pull), the Push technology is beneficial to the fact that it gives the user targeted information, which can be useful to it, but he may not know about this benefit. Initially, Push Notification technology had a relationship not to mobile applications, but to the Pointcast network engaged in the newsletter of the stock market. The same system has long been used by the courts of the United States for sending processes data subscribers. Later, Microsoft and Netscape included technology into their browsers, but due to the low speed of users connecting at that time it was ousted by Pull-technology RSS. And only then the term received wide fame after the implementation of technology by Google in Android OS (Google Cloud Messaging, GCM) and Apple in IOS 3 (Apple Push Notification Service, APNS). Using the example of the latter, consider the elementary scheme of work of Push-notifications.
- To obtain PUSH messages, the OS must register a mobile application;
- OS requests an APNS device identifier (token);
- The application receives token from the APNS server;
- The application sends a token back to the server so that the server further enjoys them to send push notifications;
- When an event defined by the developer, a server, using tokens, sends push messages through APNS;
- APNS makes newsletter notifications in the application.
What goals are pursued by push notifications?
Push notifications can be displayed on a mobile device in three places, and may be accompanied by a beep or vibration.
Limit notifications for specific applications
Some people prefer to manage their notifications, solving which notifications can be allowed for each individual application. Lollipop gives you a good control, and Marshmallow makes one more step forward, allowing you to give up authorization. The notifications control option is in the “Sounds and Notifications” section. In application notifications, you can access the settings of each application separately. It is ideal if you want to stop the application, because of which your phone is turned off every two seconds.
You can also hide the contents of the notification when your device is blocked.
How to individually manage application notifications on Android Marshmallow or newer
Manage notifications of your application on Marshmallow is very simple.
How to individually manage application notifications on Android Lollipop or older
You can limit notifications to certain applications in Android Lollipop.
You have other ways to manage application notifications on your smartphone? Tell us about them in the Комментарии и мнения владельцев.