AlarmReceiver working in incoming call android - android

i have alarm service that listin to android.intent.action.PHONE_STATE and it work good but when i have incoming call it start my alarm.
what am i doing wrong?

An incoming call is a change in phone state, so naturally that triggers your alarm if you've set your alarm service to trigger an alarm on that intent.
Take a look at EXTRA_STATE. That might help you filter down exactly when you should trigger your alarm.

Related

Can we startForegroundServie from an exact alarm's receiver in the background?

In one of the exemptions of the "cannot start foreground service from background" restriction, the doc mentions:
Your app invokes an exact alarm to complete an action that the user
requests.
Does this mean that the usage scenario below can work?
Use AlarmManager.setAlarmClock to schedule an exact alarm to trigger at time A. The alarm carries a pendingIntent that targets a registered broadcast receiver.
Time A hits, the receiver gets the intent.
In the receiver OnCreate method, we attempt to startForegroundServicewhich involves displaying a sticky notification and playing custom music with MediaPlayer.
I have implemented and tested this and it appears to be working, so I assume this is a valid use case.

Android Broadcast receiver: ignoring for a certain period of time

One of my background service has registered a broadcast receiver with the intent ACTION_USER_PRESENT. Upon receiving this I start another service. However, I wish to receive this intent only once per hour. Whats the good practice:
Should I unregister the broadcast receiver in the 1st service after my 2nd service finishes and put some alarms in the 1st service?
I just ignore the broadcast intents received for the next hour?
Any other strategy?
PS. I need to be battery efficient :)
You can register ACTION_TICK that send intents every minute and only start activity when an internal variable reach > 60 for example. But this may not be the most efficient use of battery. You can use AlarmMannager too, but I dont know how it works.
You can achieved it by AlarmService
1) Register your broadcast first.
2) When you received your intent start alarm service with repeating time
3) When alarm start you can either start service or receiver
See below link Alarm Service Alarm Service

The broadcast receiver's lifecycycle?Why my service gone?

My app runs in background. I use alarmmanager to trig a alarm every minutes.When my Broadcast receiver receive the alarm I start a service.But I found that the service only last for about 4~5 seconds.I think every time the alarmmanager trig a alarm and a new Broadcast receiver instance created.the Broadcast receiver goes quickly.So the service gone with it?But the android.os.Proccess.myPid() is always the same.I am confusing with it.
Thanks,
zhangkai

Restoring Alarms set with AlarmManager after device reboot

I want to create an Alarm for Android.
I've used so far an AlarmManager that sets on the given time and day.
And onReceive(), I have a NotificationManager that warns for a specific event.
My problem is that if the event is set for a week or month later, I may restart my device and my alarm will be lost.
Can someone explain me how can I save this alarm and restore it after reboot?
you need to use a broadcast receiver that listens for the broadcast
android.intent.action.BOOT_COMPLETED
then restart your alarms from your broadcast receiver

Getting Saved Data from Broadcast Receiver (BOOT_COMPLETED alarm)

I have a broadcast receiver for receiving the 'BOOT_COMPLETED' event. What I want to do in the OnReceive method is to re-schedule an alarm whose time is pre-defined by the user. How would I go about getting the alarm time that the user entered into the application? I tried looking at SharedPreferences but these don't seem to be accessible out-with Activity classes. Does anyone have any ideas on how I could go about getting this information?
You don't have to set the alarm at boot time. You can use AlarmManager to handle that for you. You can even set repeating alarms with it.

Categories

Resources