Change brightness on specified hours - twice a day - android

I have an array of specified hours for each day, when brightness should by changed for application which is awake 24/7. It happens twice a day.
What I want to achieve is to find the most economical way of implementation that problem.
Should I use AlarmManager or maybe there is a better sollution?
Activity is always awake...

If your app doesn't show any UI while it's awake, use the AlarmManager.

Finally, I decided to use an AlarmManager with BroadcastReceiver setting value in SharedPreferences and then in Activity I have a Handler which checks that value.

Related

Trigger an activity if the clock is match

I want to start an activity if the clock is 15.00. Is there any reference ?
Assuming i had running services in my background.
EDIT
I have value from database. Then the activity will trigger based on clock that i saved from database. So if the database has values like 01.00 , 13.00 , 22.30 then the activity will start when the phone clock match as that 3 value.
You can use an AlarmManager for that
This post will help you. Use AlarmManager to set a repeating alarm. The time can be set.
Android notification app not working properly

Change the length of the Android Alarm

The android alarm duration is basically at 1min (I think).
I would like to change it, so I can set the length/the duration at 4min for exemple (the duration of a song).
Can you tell me which methods I can call to change it ?
Can you guide me please ?
Thank you in advance !
I think you can use AlarmManager for this. http://developer.android.com/reference/android/app/AlarmManager.html
It has setRepeating method where you can set the interval you want (the second parameter is time in milliseconds that the alarm should first go off).

Android program to: Display random image for 90 seconds then switch

I'm new to android. I need to make a program that is very basic. It needs to display a random image from my drawing folder. I can do that part because frank n stein posted How To Display Random images on image view
But I need it to stay on the screen for 90 seconds (and count down) or until a user clicks a button. Can someone help? I would really appreciate it. If you post an answer please assume I know absolutely nothing...barely the basics. But I'm trying to learn. :)
You can use a for loop with Thread.sleep() or a CountDownTimer or AlarmManager or a Handler with postDelayed option.
You can use android alarm manager with broadcast receiver,you will set alarm +90 second to this time and receiver the alarm or you must to use timer.But timer is spending battery more than alarm manager.
You can follow this tutorial for alarm manager and i think you must follow :)
http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/

Adding schedule to android application

I want to create a scheduler for my app. My current idea is to create a background service which starts up on boot and listens to the date and time. This triggers my application. But I'm guessing this isn't the most efficient method. I googled quite extensively and didn't come up with anything different. Is there a more efficient way than creating a service?
[EDIT]
Making my question clearer. I'd like to make something like this.
Say I want to run the app every Monday at 10:00am how would I go about doing that? The method I concocted or something more efficient?
All you need is the system's AlarmManager in conjunction with a BroadcastReceiver which starts an IntentService.
Update: On second read, what do you mean by trigger my application? I was assuming it's non-interactive, but if it is interactive, you could bring up your Activity with the help of the BroadcastReceiver; no IntentService required then. Saves you the time monitoring either way.
Update One of the central questions you have to ask yourself is, do I want to wake up the device, such that my {app, service} is run exactly at that point in time, or is it okay to have that run immediately after the device is woken up by the user, if "another Monday 10oo am" has passed by?
Regardless of the answer to that question, you'll use the system's AlarmManager to set up a repeating alarm, either with setRepeating() or setInexactRepeating(), and with either RTC or RTC_WAKEUP. triggerAtMillis is the time delta to the next Monday 10oo am and intervalMillis is the number of milliseconds which a week has.
And that's it.
I think you need to fix the schedule of your code..
Try this code for schedule the particular functionality..
Timer mTimer = new Timer();
TimerTask mTimerTask = new TimerTask() {
#Override
public void run() {
/*your code here..*/
}
};
mTimer.scheduleAtFixedRate(mTimerTask, getTomorrowMorning2AM(), 1000*60*60*24);
}
private static java.util.Date getTomorrowMorning2AM(){
Calendar c = Calendar.getInstance();
java.util.Date date2am = c.getTime();
date2am.setHours(2);
date2am.setMinutes(0);
return date2am;
}

How to Triggering code in background in android?

I want to trigger specific code snippet at everyday 10.00AM while app will minimized pls help me?
You need to use Alarm Manager Class.
You can find suitable example HERE.
The easiest way to achieve this is setting up an AlarmManager that will fire your intent at the time you set it to.Inside your intent you can do whatever code you want.Else setting up a background service could be a good alternative,even tough takes a little more coding

Categories

Resources