Last Time Contacted - android

How does android calculate the value for last time contacted. It provides the value in integer format but I am unable to decipher the given value. For example what if I want to compare the two give values to know which contact has been contacted later. Any type of help would be appreciated.

The value you receive is returned in long format and holds the date and time information of the last time called has happened from a particular number.
It returns the milliseconds of that number.
For your reference: http://developer.android.com/reference/android/provider/ContactsContract.ContactOptionsColumns.html#LAST_TIME_CONTACTED
Now how to compute date and time here is the link:
how to convert milliseconds to date format in android?
How to compare:
There are functions "before" and "after" which tells whether the event date is before or after another specified date
Date class: http://developer.android.com/reference/java/util/Date.html#after(java.util.Date)
or
Calendar class: http://developer.android.com/reference/java/util/Calendar.html#after(java.lang.Object)
Depends which one you want to use.
I hope it helps and let me know for more info.

Every time you contact someone, (i.e. make the call Contacts.markAsContacted) the TIMES_CONTACTED should increment by 1 and LAST_TIME_CONTACTED should be updated. However, many device manufacturers have changed this functionality and it is not reliable anymore. There is an open bug for this issue which you could find at
http://code.google.com/p/android/issues/detail?id=8784&q=LAST_TIME_CONTACTED&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

Related

How to Convert a Date and Time into miliseconds that goes as an argument for Timestamp?

enter image description here
I have been trying to convert a given date and time into milliseconds as I want to upload it as a timestamp but this is giving me Exception "java.time.format.DateTimeParseException: Text '2019/2/29 17:59:00' could not be parsed at index 5" . I had also tried the tradition way of SimpleDatePickr as well which showed a out of bond exception. I can't really figure out what's going on . I know this question has been previously answered but try to understand that none of them worked for me.
You're time format is expecting a double digit number as month while you are feeding it a single number 2.
Try to zero-pad your month like this: 2019/02/29 17:59:00

Check whether specific time has surpassed using Firebase timestamp

I am stuck on a problem in Firebase where I have would like to:
Check the date and time using the Firebase.ServerValue.TIMESTAMP.
Increment the value of a variable when the date changes.
I have understood how to capture the time and date but how can I know whether the time is 2:00PM of 6 Feb has surpassed and change the value value of the variable after that. Any help would be appreciated.
Convert the date into milliseconds for both for comparison then simply perform a magnitude check.

Android system time

in my application i need to get current Date and time, every time the user inputs data with it.
I know i can use System.currentTimeMillis(), but it can give me wrong time(because it gives system time, witch can be edited by user)
So i see the only way is to call server for current time, when the user makes data input. but i am not sure that internet connection is always awailable.
Is there any way to get current time (not system time) in android, without using internet connection?
If you don't want system time you need some other source then.
There are a few possibilities that I know:
Get it from web - Internet needed
Get it from router - enabled wifi needed (NTP)
Get it from GPS - GPS fix needed
All of these aren't very helpful I believe. I don't think you can find a way of getting current time without connecting so something externally.
In my opinion you should use system time and assume it's set correctly. When it's not your application shouldn't crash and should gently know user that he has wrong content because of wrong dates ...
I believe there's no way to get the current system time without the timezone.
A good approach would be getting the current system time first
long time= System.currentTimeMillis();
And then getting the correct TimeZone to handle it
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone();
long dateInMillis = System.currentTimeMillis();
String format = "yyyy-MM-dd HH:mm:ss";
final SimpleDateFormat sdf = new SimpleDateFormat(format);
String dateString = sdf.format(new Date(dateInMillis));
Use dateString as your variable which contains current date time as timestamp.
Well, I googled about your topic, and i got logic solution but not tested:
" Use The network-provided values ", in the android phone settings, it;a as shown in the picture bellow:
The screen I show is DateTimeSettings. The checkbox "Use network-provided values" is associated to the shared preference String KEY_AUTO_TIME = "auto_time"; and also to Settings.System.AUTO_TIME
This settings is observed by an observed called mAutoTimeObserver in the 2 network ServiceStateTrackers: GsmServiceStateTracker and CdmaServiceStateTracker.
Both implementations call a method called revertToNitz() when the settings becomes true. Apparently NITZ is the equivalent of NTP in the carrier world.
Bottom line: You can set the time to the value provided by the carrier thanks to revertToNitz(). Unfortunately, I haven't found a mechanism to get the network time. If you really need to do this, I'm afraid, you'll have to copy these ServiceStateTrackers implementations, catch the intent raised by the framework (I suppose), and add a getter to mSavedTime.
For more informations, i suggest you to check this link here
Use the ScheduledExecutorService with scheduleAtFixedRate to send you "clock ticks". If the user initiates an event and the number of accumulated "clock ticks" since the last event doesn't match the time change on the system clock, you're being lied to.
You don't need to know the correct time. You need to know the correct interval. This can be done with any periodic source, even a local one. (Timekeeping is two jobs: a metronome and a labeler for the intervals of the metronome. You don't want the system's labels because they can be made to lie, but the metronome ticks on even if the labels are changed.)
I'd recommend a relatively slow tick rate (<= 1 tick per minute) and rather sloppy comparisons (within 2%, maybe) since the various clocks may not be all that accurate.

Using a DatePicker in Android dev: How do I compare the date picked to today's date?

I'm really stuck with a certain problem and I'm hoping someone can help me understand the problem and come to a solution. I've looked online a fair bit but can't see an answer unless it's been staring me in the face :-/
Basically, I'm creating a very basic TV Guide app. It parses data from an RSS feed which has days offset (yesterday was -1. today is 0, tomorrow is 1, etc etc) and I'm trying to implement a DatePicker that allows the user to see what is on a particular channel when they select yesterday, today, tomorrow, etc.. but if they pick a date that is out-with the range (at the moment it's a week in advance), a simple Toast message will be displayed.
My questions I guess are, firstly, how do I use maybe an IF ELSE to either parse the specific channel data for the day the user wants or display an error Toast message, and, how do I go about converting the days from what the user has put in compared to the actual date today into integers? If they select yesterday's date it will go to URL "http://example.com/-1/channel", if they select tomorrow's date it will go to URL "http://example.com/1/channel" etc etc etc.
Code is available if anyone needs to see it, but I think if someone would be kind enough to explain the logic, I'd like to see if I can come to the answer myself...
Thanks a lot folks!!
You should use a DatePicker to allow the user to choose the when.
Time in Android is stored on a long (not an int). And the long time can easily be converted back and forth between long (always milli-seconds) and a Date object.
The Date object gives you all sorts of tools to compare before and after, look at months, minutes, hours, etc.
The current time is determined by:
long nowMs = System.currentTimeMillis();
int nowSec = (int)(nowMs / 1000);
There is also a very important Calendar object. This allows you to parse textual date formats as delivered by your http functions in and out of various dates.
For example:
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss Z");
String text = sdf.format(cal.getTime();
You will have to put all these tools together with a DatePicker example such as the one here Create a DatePicker to complete your TV Guide application.
Reference:
Date
Calendar
DatePicker
EDIT : Check David's Answer its better.
First Filter the date selected with today's date. You can compare it by date.isbefore(date) or date.isafter(date) these booleans will let you tell know if a date is of past or future or present. then to further calculate the days inbetween you can make a method with switch statement that will basically convert the selected date and the current date into miliseconds(Date.getTimeinmiliseconds)
if the date is of past take the difference of present time in miliseconds and past date in miliseconds. If the date is of future do the opposite. Take the difference and convert it to days difference with appropriate sign(negative/positive).
Please refer this link for a better coding example

gps time vs device time

I create a GPS tracking, but when I use DDMS to send coordinate to the emulator and I want to get time of this coordinate through
Date date = new Date(gpsPos.getTime_stamp()); //gpsPos is an obj
gpsPos.setDate_time(date.toString());
The time I got from the function in miliseconds and I converted it to date using date class in java, but the date I got from converted is different from the real date of device.
How can i get the time location equals real time ? any idea? thx
what is the different between date.toString() and date.toGMTString()?
EDIT:
how can we solve it i want my gps time is equal to the real time (logic enough) in order to use it test sth later?
Date(milliSeconds) will create the Date object based on GMT, Date.toString will create a string based on your locale (by default but can be modified). If the milliseconds you used to create the Date object is actually based on your Locale then your time will be off by 4 hours if you're in EDT as an example.

Categories

Resources