AlarmManager not working after sometime in some Chinese phones - java

I am using an IntentService in my app which is to be triggered everyday at a specific time.For this, I am using Alarm Manager to trigger my service. In most of the phones (like Samsung,Sony,etc) this is working perfect.But in Chinese brands like Vivo, Xiaomi, etc the Alarm Manager works for sometime but doesn't works for a period of 24 hours. So, I had to manually suggest to my users to allow app autostart from their app permissions(it is also quite uncomfortable for vivo users due to their different android versions).
I used RTC_WAKEUp, but that also doesn't seems to work for chinese handsets
I want to make my app flawless working without the need of user(to allow permissions). How can I acheive this? wishes some help from you.Thanks
Intent intent=new Intent(this,MyAlarmService.class);
PendingIntent myPendingIntent=PendingIntent.getBroadcast(this,0,intent,0);
myAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,timeInMillis,AlarmManager.INTERVAL_DAY,myPendingIntent);

Related

Sometimes AlarmManager not trigger if I close my app, sometimes it does trigger. What is the problem with that?

I don't want to use services run in foreground because they uses resources. If I open my app later the alarm triggers. One more point, if I whitelist my app from battery optimization it works well. Any suggestion?
Some devices do not permit applications from running in the background, or from being started by AlarmManager. These applications need to be "whitelisted" or added to a list of apps permitted to do this. Different manufactureres handle this differently. If you are running your app on such a device, you will need to have the app (manually) added to the whitelist or list of protected apps, or list of background apps, or whatever.

Using AlarmManager for periodic task Android

I am new to Android. I want to develop an app that is going to do something every 20 minutes: if the user is in the app, they just get a message, else, the app will set a dialog and if the user accepts that dialog, the app will open and the user will get that message.
I have searched how to do that and ended up using alarm manager and everything went fine. However, the question is that if using alarm manager is good for this situation. If not, why? And what is the solution? I had read somewhere that work manager is also good.
WorkManager will not be useful in a case like this when device enters Doze mode.
WorkManager adheres to power-saving features and best practices like Doze mode
I have seen that even after white listing the app, (removing from battery optimisation), if device is left unused, stationary, unplugged, WorkManager work is delayed until the next maintenance window, sometimes hours of delays.
AlarmManager can be used but documentation recommends
Exact alarms should only be used for user-facing features. Learn more about the acceptable use cases for setting an exact alarm.
FCM is another option that could be considered in doze mode.
Edit: WorkManager is definitely recommended for persistent onetime or periodic works which are not time sensitive, where combination of constraints can be applied.

Make Chathead bubble run forever in android

Hi I am trying to make a chathead bubble, like the one facebook has, for an app in android studio. I have been able to successfully display the bubble using Overlay and make it a service which continues to run even after the app is closed (not killed). However when I open another app or if I dont use my phone for more than 10 minutes, the chathead bubble disappears, unlike Facebook's bubble. How can I go about making the bubble display on the home screen and other apps for a longer period of time(potentially forever)?
For context, I used https://www.androhub.com/android-floating-widget-like-facebook-messenger-chat-head/ to make the bubble, using a View and a Service.
Thanks in advance
Your app's service will get killed by the android system to save battery. There is no exact and easy way to do that. You have to implement multiple methods to do that.
Use Foreground Service(You may have already doing this but just in case if not.)
Ask for permission to restrict Battery Optimization.
In some devices like Xiaomi and Vivo, you need special permission to always run in the background ask for that.
Ask the user to lock the app in recent tab so it won't get killed by the system.
If you are implementing the service, override onStartCommand() and return START_STICKY as the result. It will tell the system that even if it will want to kill your service due to low memory, it should re-create it as soon as memory will be back to normal.
If you are not sure 1st approach will work - you'll have to use AlarmManager http://developer.android.com/reference/android/app/AlarmManager.html . That is a system service, which will execute actions when you'll tell, for example periodically. That will ensure that if your service will be terminated, or even the whole process will die(for example with force close) - it will be 100% restarted by AlarmManager.

Open Alarm feature of Android?

I have read many questions regarding how to set Alarm through your application. But here I want to open the Alarm built-in function or option of Android through my application. I don't think that Alarm is an application of Android; if it's not so, how can we get access to this feature of Android?
Android OS is providing Alarm Manager component, and all manufacturer provide own way for set Alarm in the device, so all device has different inbuilt Alarm application with different package name, so you can't able to use that package name hardcoded in your own app for open inbuilt app for all the devices.
Here You have to develop your own application with alarm manager component with your own way, Not any options for access device inbuilt setting.
I don't know why but Android does not give access to the some of built in features like Alarm
Developer option etc
check out this one https://developer.android.com/training/scheduling/alarms

detect when user sets alarm Android

I am trying to execute an action when the device detects that the alarm is set by the user.
Does anyone know how I can go about doing this in code? Would appreciate any advice.
Thanks
There isn't a unified "action" the user performs that will set the alarm. It would probably not even be correct to refer to it as "the alarm", because the alarm is just another application. The user can be using the stock alarm shipping with Android (in the Clock application, I would guess?), the phone manufacturer might have bundled its own alarm app with the phone, or the user might have downloaded a 3rd party alarm application from Android Market.
I would guess that the only thing all those different apps could have in common, is that they in some way could use the AlarmManager class to control when the alarm should go off. But I don't think this is something you can listen to (and it is also lots of other apps other than alarm apps that also use the AlarmManager).

Categories