Measure time per game session - android

Is it possible to measure the time a user has spend in my game (not overall, only per one session), using only Parse's methods, without any additional code from me?
Or if not possible, using Google Analytics?

You could use the user timings, from https://developers.google.com/analytics/devguides/collection/android/v4/usertimings. This would mean saving the current timestamp in onCreate, and logging it in onDestroy, or a related place.

Related

Android - Implementing a means to get 'real' time in offline apps

Background
The company I work for is creating an app that collects information from various device events and sensor data.
One of the things we would like to be able to do is use time to process the data when it gets to the server.
We would also like there to be an acceptable amount of "offline time" allowed, i.e., the app could be used for its purpose even while offline until the next server data update is required etc.
Problem
One issue is that the user can just change the device time.
We overlooked this, and have been able to successfully generate events for the previous day, which would mean that our app could be fooled in situations where device time is a factor, which is very uncomfortable.
Imagined solutions
Obviously I can ensure that the app is always sync'd to the server before it starts collecting important data, and then use server time and make all further time relative to that.
Another way might be to keep a reference to something like the last update time or even the app install time and work out time relative to that.
Questions
How do people get around this typically?
Are there any libraries out there that can be used to enforce real device time?
Thanks guys

Android: calculating time away from app

In my app, I'd like to keep track of time away from the app, so that if the user is away for say, 2 hours, and come back, they receive 1 in game currency.
In practice I could easily do this by using a date object to get the current time in onStop, saving that date object, and comparing it to a new date object when they return.
However, I have a feeling this can easily be spoofed by change the internal date settings.
Is there a more secure way? Should I just put a cap on how many hours away you can bank up? I'd love some insight. Thanks as always.
you can try to make more secure code in the app, but the safest way is to request something from a server
if you are app is already using internet permissions consider making an HTTP request to get time.
look at this site for example
http://www.timeapi.org/
if you have backend to support your app that would be extra better
if you are not using internet permissions it might not be worth it to add it just for this, you might consider a different "offline" solution

Approach for GMaps real time object movement updating

I am making an Android game. So, people are able to create groups/parties between them and I would like to give them the ability to view each member of their group moving on the Google Maps in real time. This means that I have to find a good way to update each client’s map markers in real time or pseudo-real time at least.
Would an approach with a DBMS be fine or that would be too costly? In this approach, every client should be responsible to update the DB every so with their current coordinates and thus everyone can make queries to view every other party member's lastly updated location. Making this happen within small time intervals will give the feeling to users that people are moving on Map in real time.
On the other hand, would a peer-to-peer approach handle this case in a better way? Like every group/party runs on its own by letting players exchange info between them containing everyone's new coordinates every so (interval). I believe that the second approach is better because it does not give load to our server, but there may be drawbacks. I am not sure however how easy this would be to be implemented and if Android API provides something good for this case.
Any opinion/suggestion/comment is very welcome. Please I would like to hear what you are thinking, since I have no experience on this subject and hence anything might be helpful.
Thank you in advance! Please enlighten me :)
Since the options are all a bit "costy" in terms of connection/operation, i would suggest you to check at the MQTT protocol. It's used as M2M connection with an eye to optimization. It was created for Internet of Things purposes.
I've used it for non-android projects but it can be used also for that.
You only need a server (broker) and i suggest Mosquitto (which is lightweight).
Then every one can subscribe to a topic like: "/location/update/+" using + wildcard means every topic that is one level after "update" topic.
Then every one publishes his own position to the topic "/location/update/{MYID}" and the others will receive the position.
Usually the position are retrieved only when connected, but you can manage to support a sort of "hanging" subscription by using QoS=2 when subscribing and connecting always with the same ClientName.
Does it help?

Android - Last screen lock time

Is there a way to find the last time or the time spent since the user locked/unlocked the screen? Is there any log which stores this information?
I am trying to track user (in)activity and looking for the simplest possible way to do it. I know it can be done by continuous tracking through a service perhaps, but was trying to avoid doing that.
It seems that this cannot be done.
I ended up creating a new service which track the last screen lock/unlock and save the time myself.

Time since the app is open in android

Hello
In my android application i would like to get Time since when the app is opened.
Initially what i tried was getting the time when the app is loaded from the server and then taking the difference with the current time from the device.But by doing that if the user changes the time then i willnot be getting the actual time.
Its not posiible to hit the server again for the same.
Is there any way to achieve this in android?
Please share your valuable suggestions.
Thanks in advance:)
Try the "SystemClock" class, "uptimeMillis()" method.
Store the result in a variable when the app starts.
Echoing what I said for your other question, you first need to become familiar with the activity lifecycle and understand the novel meanings (almost meaninglessness) of common words like "open" and "start" in the life of an android app.
There isn't any way you can prevent the user from changing the system time - you just don't have the right to do that to users. Normally this should be a rare event, unless you do something that makes them want to, such as lock them out of a free version of your app after so many minutes. (However if the phone is on a mobile network, presumably the mobile network occasionally adjusts its time to correct for errors in the device's oscillator, or administrative time changes)
What you can do is check the system time on every entry point to your application. If it ever goes backwards, well... something is going on. If the clock has been set back, you could assume no time between the calls with the negative time difference and resume your time meter from there, at least keeping all the previous used time in your record.
It may be that there are cpu cycle counters which you could query and correlate to system time, but this may be highly device specific and may in fact be resettable. And it may get weird if the cpu frequency is demand throttled.
You might be able to set a countdown timer as a bound on the maximum possible time between entry points at which you could meter. I don't know if these work reliably across system time changes or not - ideally they would. Testing or reading the source will reveal.
Use elapsedRealtime in your onCreate() store it. More reliable.

Categories

Resources