I know this is easy, but how can i make my widget update every 24 hours this what am presently trying,
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:autoAdvanceViewId="#id/stack_view"
android:initialLayout="#layout/cepf_appwidget_layout"
android:minHeight="100dp"
android:minWidth="180dp"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="3600000" >
</appwidget-provider>
24 hours = 24 hours * 60 minutes * 60 seconds * 1000 milliseconds = 86400000 milliseconds. Put this value to the android:updatePeriodMillis
P.S. Your current frequency is 3600000 milliseconds. This is: 3600000 / 1000 = 3600 seconds / 60 = 60 minutes = 1 hour.
Well, it's basic convertion. 1 hour is 60 minutes, 1 minute is 60 seconds, 1 second is 1000 milliseconds.
Related
I'm making a project on android studio.
I must convert a number into an hour, minutes and seconds date.
The number is: 0,18865386
The result must be: 04:31:40
I've obtained this date whit excel (used for test calc) just changing the cell format to HOURS but i don't understand how to calculate it.
Any solutions?
1 corresponds to 24 hours.
In hours: 0,18865386 means 24 x 0,18865386 ~= 4,5 hours which corresponds to your 04:31:40.
If you need more precision, e.g. in seconds:
The number of seconds in a day = 24 x 60 x 60 = 86400.
Then 0,18865386 means 86400 x 0,18865386 = 16300 seconds = 04:31:40.
time Range picker to select time range, with hours mins and seconds android
Is there any library which supports seconds also
the only one i found was
https://github.com/tittojose/TimeRangePicker
but it does not support seconds
use this,
int time=(picker.getCurrentMinute() * 60 + picker.getCurrentHour() *
60 * 60) * 1000;
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
String formatted = format.format(time);
I am using alarm to start service at every 15 days once. Alarm is initiated at the first time of installation. Every 15 days once alarm trigger that service properly, but At the time of initiating alarm the service started.I dont want to start the service at the time of installation. how to stop this.
I dont whether i am using wrong format?
Note: Apart from this condition, I am not start service anywhere.
Intent intent = new Intent(context, InitiateService.class);
PendingIntent pIntent = PendingIntent.getService(context, 12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 15 * AlarmManager.INTERVAL_DAY, pIntent);
this what i used in manifest file.
<service android:name=".service.InitiateService" />
this is my code of initiating alarm for starting service at every 15days once.
Guys If any one found any wrong in my question, Apologies me and Please correct those mistakes and answer me.
it is because you used System.currentTimeMillis()
try this
System.currentTimeMillis()*(15 * AlarmManager.INTERVAL_DAY)
alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()*(15 * AlarmManager.INTERVAL_DAY), 15 * AlarmManager.INTERVAL_DAY, pIntent);
#Mehul Gajjar is correct about System.currentTimeMillis()
so you might wanna replace
System.currentTimeMillis()
with
(15 * 24 * 60 * 60 * 1000 * System.currentTimeMillis())
Explanation :
System.currentTimeMillis() will set Alarm to current time, so your service will start straight away. setting Alarm after 15 days will solve your problem.
15 * 24 * 60 * 60 * 1000 will be equals to 15 days. multiplying it with current time-miles will give you current time after 15 days.
in-short your code would be like
alarm.setRepeating(AlarmManager.RTC_WAKEUP, (15 * 24 * 60 * 60 * 1000 * System.currentTimeMillis()), 15 * AlarmManager.INTERVAL_DAY, pIntent);
I hope this will help you.
How to setup service to something (api request) everyday at particular time.
I dont know.
Right now I thing about two options:
1. Setup timer and every hour check the time and if it right, do a request.
2. setup the alarm, by alarmManager, but I dont know how to do it.
Another imported thing is the request must be a little random.
About 3-10 minutes, to prevent blocking the server by too many
request at the same time.
Take a look at this tutorial for scheduling events with an AlarmManager.
For the interval of 3-10 minutes you could just add something like
int rand = (int) (Math.random() * 1000 * 60 * 7 + 3 * 60 * 1000);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + rand, sender);
I'm getting a data which contains a certain number.
I need to find how many hours, minutes and seconds it stands for.
for example:
I'm getting the number 248 which means:
00 hours : 04 minutes : 08 seconds
Any ideas would be really apprieciated!
Determine hours, minutes and seconds like this:
int hours = (int) (time / 3600);
int minutes = ((int) (time / 60)) % 60;
int seconds = time % 60;
Alternatively, you can determine minutes like this once you know the hours:
int minutes = (int) ((time - hours * 3600) / 60));
You need to multiple it to milisec.
Like 248*1000;
Then Date d = new Date(248*1000);
And youll have data object.
d.getHours(). for example
also you can use SimpleDateFormat. Which can format data with some pattern and output it to string
Like yyyy-MM-hh HH:mm
you have to define first, how this number is build up, e.g. why it can not stand for
00 hours, 02 minutes and 48 sseconds