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).
Related
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.
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
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);
I find it really hard to debug my app using Gimbal Places.
I have my Places/Communications set up and sometimes they do fire but once they fire I do not know how to reset the trigger so that I can check if its working. I have to walk up and down the street and then sometimes it does not even fire.
Is there a way to reset the trigger in my program ?
Thanks
Sorry for the late response.
The easiest way to create Gimbal Place Events, which in turn can generate Communicate Events, is to use a Gimbal Beacon. You can purchase the Series 10 for $5 at the Gimbal Store. Powering the beacon on will trigger a Place Event once it leaves programmable mode, about 10 seconds. Then you can create a departure event by powering the beacon off, by default it will take 30 seconds to depart (configurable in Gimbal Manager). Once you get the departure event you can trigger another arrival event by powering the beacon back on.
You can also use geofences as described above to do this testing if a beacon is not available. The issue with a geofence is generating the departure, which as described above requires you to actually leave the geofence. You can also generate arrival events by uninstalling and reinstalling the application. Each time it starts and you are in the geofence it will generate an arrival event.
Hope that helps.
The best way is to use USB Beacons, so you can plug/unplug them for testing. But if you prefer to use geofences there are apps that can fake your location with Android (I guess something similar for iOS).
But the best think to test it are USB beacons, at least for myself.
I am developing an Android app that allows sports team coaches to update the attendance for events like training/matches. A feature I would like to add would be to display a notification on the device to remind them that they need to update the attendance for the event when it has started.
I have been reading online a bit and it seems that push is the preferred method for data that is changing. But because i know the start times of the events, would it be better to create a background service using something like the following?
https://stackoverflow.com/a/9933130/2039505
I basically want the user to receive a vibrate notification which when they click on it, it will open the events attendance screen. Hopefully someone will have some insight into which option is best!
Since all you need is a notification on a timer, the AlarmManager would be the best way to go.
If you used Push Notifications(GCM), that would require server side code and a method to store the device id to send the notification to.
Overkill if you ask me.
Here are links to the official documentation and example code:
Official documentation
Vogella's example on services