Different Android dates in emulator and real device - android

I'm experiencing a very strange problem with Date objects in Android,
when I run the following code I get different dates in the emulator and in the real device. (str1 and str2 come from the following json result
json file)
String str1="1450967458";
String str2="1450980000";
Date dstart=new Date((long)Long.parseLong(str1)*1000);
Date dend=new Date((long)Long.parseLong(str2)*1000);
Log.i("VILLANUEVA","START:"+dstart.toString());
Log.i("VILLANUEVA","END:"+dend.toString());
Dates in real device:
... I/VILLANUEVA: START:Thu Dec 24 15:30:58 CET 2015
... I/VILLANUEVA: END:Thu Dec 24 19:00:00 CET 2015
Dates in emulator(These are the correct dates)
...I/VILLANUEVA: START:Thu Dec 24 09:30:58 EST 2015
...I/VILLANUEVA: END:Thu Dec 24 13:00:00 EST 2015
It seems to be a difference of 6 hours between the device and the emulator. I've tested with Calendar class and I get the same difference. Any help would be appreciated. Thanks in advance.

Related

gson: Wrong parsing time in some Android device

I got wrong value when using Gson in some Android devices.
Below is json
JSON
{'Time':'1900-01-01T11:00:00.000+08:00'}
Below is my code for testing
new GsonBuilder().create().fromJson("{'Time':'1904-01-01T11:00:00.000+08:00'}", Info.class);
The result is in correct: Fri Jan 01 10:36:42 GMT+08:00 1904
new GsonBuilder().create().fromJson("{'Time':'1905-01-01T11:00:00.000+08:00'}", Info.class);
The result is correct: Sun Jan 01 11:00:00 GMT+08:00 1905
The android version is 10 (API 29), MIUI 12
May I know anybody has this issue

UsageStatsManager not returning correct weekly or monthly results

Question
I want to retrieve a list of UsageStats per week or month. However, the output often has overlapping intervals, e.g. Wed Apr 29 until Mon May 04, when I'm requesting monthly data (see the latest result of the time stamps below).
So my question is: how can I cleanly get the usage stats for a particular week (e.g. Mon - Sun) or month (e.g. Apr 1 - Apr 31) using the UsageStatsManager?
Background
In my Android application, I'm using the UsageStatsManager to retrieve the total time in foreground per week/month. This post about how to use the UsageStatsManager has been very helpful already, as well as this post about the UsageStatsManager producing the wrong daily results (I'm using that method for the daily usage stats, which is working fine now).
Problem
The trouble starts when I try to retrieve the usage stats for weekly/monthly interval. The UsageStatsManager documentation states that
Usage data is aggregated into time intervals: days, weeks, months, and years.
But the output I get from querying the UsageStatsManager is very different. An example of how I'm retrieving the list of UsageStats objects for the last two months:
Calendar endCalendar = Calendar.getInstance();
long endTime = endCalendar.getTimeInMillis();
Calendar startCalendar = Calendar.getInstance();
startCalendar.add(Calendar.MONTH, -2); // since two months.
long startTime = startCalendar.getTimeInMillis();
UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
List<UsageStats> result = usm.queryUsageStats(UsageStatsManager.INTERVAL_MONTHLY, startTime, endTime);
However, when I go over the List<UsageStats> result and log the time stamps of the packages and their foreground time, I get a bunch of time stamps, but they are not in a monthly interval at all. An example of time stamps I retrieved for the Contacts app from the result:
ForegroundTime: 4447 first=Wed Mar 04 03:53:28 GMT+01:00 2020 last=Fri Mar 06 11:46:18 GMT+01:00 2020
ForegroundTime: 176383 first=Fri Mar 06 11:46:18 GMT+01:00 2020 last=Tue Mar 17 07:53:54 GMT+01:00 2020
ForegroundTime: 14337 first=Tue Mar 17 07:53:54 GMT+01:00 2020 last=Tue Mar 17 20:03:31 GMT+01:00 2020
ForegroundTime: 0 first=Tue Mar 17 20:03:31 GMT+01:00 2020 last=Fri Mar 20 14:32:26 GMT+01:00 2020
ForegroundTime: 0 first=Fri Mar 20 14:32:26 GMT+01:00 2020 last=Mon Mar 23 00:12:11 GMT+01:00 2020
ForegroundTime: 0 first=Mon Mar 23 04:27:16 GMT+01:00 2020 last=Mon Mar 23 17:00:29 GMT+01:00 2020
ForegroundTime: 0 first=Mon Mar 23 17:00:29 GMT+01:00 2020 last=Sat Mar 28 00:52:10 GMT+01:00 2020
ForegroundTime: 0 first=Sat Mar 28 00:52:10 GMT+01:00 2020 last=Fri Apr 03 06:45:08 GMT+02:00 2020
ForegroundTime: 81481 first=Fri Apr 03 06:45:08 GMT+02:00 2020 last=Thu Apr 09 18:04:05 GMT+02:00 2020
ForegroundTime: 0 first=Thu Apr 09 18:04:05 GMT+02:00 2020 last=Thu Apr 16 10:31:23 GMT+02:00 2020
ForegroundTime: 157189 first=Thu Apr 16 10:31:23 GMT+02:00 2020 last=Sun Apr 26 02:10:31 GMT+02:00 2020
ForegroundTime: 0 first=Sun Apr 26 02:10:31 GMT+02:00 2020 last=Wed Apr 29 13:21:12 GMT+02:00 2020
ForegroundTime: 43516 first=Wed Apr 29 13:21:12 GMT+02:00 2020 last=Mon May 04 17:45:43 GMT+02:00 2020
which seems to be partitioned almost randomly into intervals.
Any links/explanation as to why UsageStatsManager has this behaviour, or an example of an open-source application that is using the UsageStatsManager for querying weeks/months/years would be very helpful. Thanks in advance.
I might not be able to solve the issue but I will suggest a way around it which is using queryEvents function for all of them - daily, weekly and monthly data.
Querying weekly data(data of last 7 days) by this function is similar to querying daily data by it. (you mentioned that you have already implemented the function for daily data)
As for monthly data, you cannot directly use the function since events are kept by system for around one week as said in documentation. You need to store usage data in a local database and query from it.

Google Calendar producing different result between importing from Android App vs Web and Iphone

I'm wondering if there's anything wrong specified within the .ics file I generated, it's a follow up to this thread in which the solution has been implemented but in this particular case either I found an App's bug or something not being implemented correctly from our side.
Given .ics file with content as below
BEGIN:VCALENDAR
PRODID;X-RICAL-TZSOURCE=TZINFO:-//\, Inc.//NONSGML website.co
m//EN
CALSCALE:GREGORIAN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID;X-RICAL-TZSOURCE=TZINFO:America/Los_Angeles
BEGIN:STANDARD
DTSTART:20181104T020000
RDATE:20181104T020000
RDATE:20191103T020000
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
TZNAME:PST
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20190310T020000
RDATE:20190310T020000
RDATE:20200308T020000
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
TZNAME:PDT
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
CREATED;VALUE=DATE-TIME:20190221T110121Z
DTEND;TZID=America/Los_Angeles;VALUE=DATE-TIME:20190308T100000
DTSTART;TZID=America/Los_Angeles;VALUE=DATE-TIME:20190308T090000
DTSTAMP;VALUE=DATE-TIME:20190221T110121Z
ATTENDEE#<Client 1122742 "test1 account">
UID:6bOpCpTxArFlX3jvFD7NNLuROX#website.com
DESCRIPTION:One Hour Appointment
URL:https://app.local.website.com/appts/UQ4hwz3RJw
SUMMARY:Appointment with BUG_LOCAL
ORGANIZER;CN=Hakim Ahmad;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:mailto:notif
ications+development#email.website.com
RRULE:FREQ=WEEKLY;UNTIL=20250316T070000Z
SEQUENCE:0
END:VEVENT
END:VCALENDAR
In this test, with single google account, if I import the file from Web interface as in per Import events into Google Calendar. I will get result as following for:
PST-8:
screenshot for PST-8 from web import
started on 8th March 2019, 9am
PST -> PDT switch on 10 March 2019, 2am*
started on 15th March 2019, 9am
started on 22th March 2019, 9am
etc..
GMT+8:
screenshot for GMT+8 from web import
started on 9th March 2019, 1am
PST -> PDT switch on 10 March 2019, 6pm*
started on 16th March 2019, 12am
started on 23th March 2019, 12am
etc..
In contrary to result generated from android import as following for:
PST-8:
screenshot for PST-8 from android import
started on 8th March 2019, 9am
PST -> PDT switch on 10 March 2019, 2am*
started on 15th March 2019, 10am
started on 22th March 2019, 10am
etc..
GMT+8:
screenshot for GMT+8 from android import
started on 9th March 2019, 1am
PST -> PDT switch on 10 March 2019, 6pm*
started on 16th March 2019, 1am
started on 23th March 2019, 1am
etc..
Also tested with Mac Calendar and iOS Calendar which produce result the same as the web imported one.
This is tested from multiple android devices, so the 'bug' consistent across android Google Calendar app.
Also checked if the timezone upon importing play any role which it doesn't.
Is there anything I can do about this? Had already contact to Google through multiple channel but cannot get any response.
some references:
* PST-8, GMT+8 comparison of time switch on 10th of March 2019
Additional References For Answer's Follow up:
similar .ics translated to zulu time:
BEGIN:VCALENDAR
PRODID;X-RICAL-TZSOURCE=TZINFO:-//\, Inc.//NONSGML website.com//EN
CALSCALE:GREGORIAN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
CREATED;VALUE=DATE-TIME:20190221T110121Z
DTEND;VALUE=DATE-TIME:20190308T180000Z
DTSTART;VALUE=DATE-TIME:20190308T170000Z
DTSTAMP;VALUE=DATE-TIME:20190221T110121Z
ATTENDEE#<Client 1122742 "test1 account">
UID:6bOpCpTxArFlX3jvFD7NNLuROX#website.com
DESCRIPTION:One Hour Appointment
URL:https://app.local.website.com/appts/UQ4hwz3RJw
SUMMARY:Appointment with BUG_LOCAL
ORGANIZER;CN=Hakim Ahmad;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:mailto:notifications+development#email.website.com
RRULE:FREQ=WEEKLY;UNTIL=20250316T070000Z
SEQUENCE:0
LOCATION:Los Angeles
PRIORITY:5
END:VEVENT
END:VCALENDAR
Looks like you are facing the same problems as I did, too.
If you cut the timezone crap and note everything in Zulu-time, it works. At least it did for me.
DTSTART:20190226T123456Z
I've posted my solution here: How to generate an iCalender entry that works on Outlook, Android and iOS

plotting real time csv data in android

By using arduino, python serial I am able to log data from a temp sensor from dev/ttyACM0 into a file timetemp.csv
which looks like
Wed Jun 12 12:59:45 2013,27
Wed Jun 12 12:59:46 2013,27
Wed Jun 12 12:59:47 2013,27
Wed Jun 12 12:59:48 2013,27
Wed Jun 12 12:59:49 2013,27
Wed Jun 12 12:59:50 2013,26
Next thing I want is to show a realtime plot of time-sensordata preferably in android client by setting up the system(where the csv file resides) as a server...Will this be possible using the androidplot or any other plot utility like Rgraph...What are your suggestions
Yes you can use androidplot for it. It should be possible. Also you can do it by yourself.
You can look into this discussion for reference code.
Easiest way to plot array of floats

change TimeZone display type from new java.util.Date() in android

When I print the new java.util.Date() it prints this in Android
Thu Feb 22 05:30:00 Asia/Calcutta 2007
I need this to be print as Thu Feb 22 05:30:00 IST 2007
please help
Alright guys I got my problem solved. Here is the solution what I adapted
I had the date in format in dd-mm-yy which I need to convert like Thu Feb 22 05:30:00 IST 2007
so I just created the object of the SimpleDateFormat class with the desire format suiting the format Thu Feb 22 05:30:00 IST 2007 and finally called format() method on SimpleDateFormat instance

Categories

Resources