plotting real time csv data in android - 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

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.

Different Android dates in emulator and real device

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.

How to make sure if a download is resumable

I am creating a downloadaccelerator library
Is there any way to know before starting a download from a link weather the server supports resuming downloads/downloading file reange . Because if it does then i ll use multipple connections and download ranges or else i ll download the whole file normally
thank you
Similar to GET header to get the required html page, we have something called as HEAD header.
When you send a HEAD request for an URL we get a set of values for the URL
Example: if you want to know details of
http://www.wgz.org/chromatic/perl/IntroTestMore.pdf
Send a HEAD command to the URL, the response will be
Date: Mon, 03 Nov 2008 06:29:09 GMT
Accept-Ranges: bytes
ETag: "156046f-11889-3a578cd2bf2c0"
Server: Apache
Content-Length: 71817
Content-Type: application/pdf
Last-Modified: Thu, 11 Jul 2002 04:53:07 GMT
Client-Date: Mon, 03 Nov 2008 06:29:10 GMT
Client-Peer: 167.168.132.148:8080
Client-Response-Num: 1
Intresting Values: Accept-Ranges, Content-Length
Accept-Ranges: bytes tells that server is ready to give files part by part as requested
More info here: http://www.crazyengineers.com/community/threads/how-does-resume-download-work.7396/

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