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?
Related
I have been searched for a long times, but I cannot solve this.
I am developing app usage appplication, and I want to make user can restrict app usage time.
lets say user want to restrict Youtube app usage time for 10 min.
1.
How can I make notification or toaster when Youtube app usage reach 10 min since user click button?(I know event handling)
can I make observer even my app goes backgroud? or even after detroyed?
Base on my search registerAppUsageObserver looks like what I want to, but I cannot use it since its #hide
public void registerAppUsageObserver(int observerId, #NonNull String[] observedEntities,
long timeLimit, #NonNull TimeUnit timeUnit, #NonNull PendingIntent callbackIntent)
I can try to use it by reflection but I think its not recommended.
I got one more good source link but I don't know how to use it.
please help me. thank you.
I've done a fair bit of work in this area. I'd like to direct you to my smartCBT GitHub that reviews in a given period of time what a person has been using their apps for (https://github.com/kris-geyer/smartCBT; in particular, check out https://github.com/kris-geyer/smartCBT/blob/master/app/src/main/java/kg/own/smartcbt/ViewModel/RetrieveUsageRecords.java).
First off, I wouldn't trust the usage stats manager. It's been very unreliable in the past for me. I think what you want to assess usage is usage events (https://developer.android.com/reference/android/app/usage/UsageEvents.Event). These give you a much more fine-grained account of android app usage which seem much more accurate. You will need to get special permission for this. I've actually, empirically tested the accuracy before and it is very high.
For the overall structure of what your app needs I think you want a foreground service that runs in the background routinely logging what the person is using their phone for. This database is only updated when apps are changed, so handling this might be a little tricky but you'll manage.
When the app has identified that the allotted amount of usage time for a particular app is up, then it can direct the user back to your app by launching a new activity from the foreground service. I'm not sure if this is still possible, the android permissions seem to change so quickly. What would be really cool is if you can get the app to play videos of the user telling themselves that they've used their phone too much and be productive.
Best of luck. :)
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
Though as a beginner, I am trying to develop an android app which is story based, i will like to know the best way to serve content to the user, i mean like a continuous update of content, just like updating news by the hour. As users will install just once, how will they get the latest content of my news or story based app.
I have access to domain names and hosting if it requires uploading such content through a domain.
from your experience, what is the best method to achieve this? I humbly await a response, thanks
So given the clarification in the comments this is the answer:
The best way is PUSHING the content to the user's device.
Generally speaking, the two ways for a new content to reach an app are :
1.polling your server (or any third-party server) for new data every,say, 20 minutes. The disadvantage of this method is that it drains the battery. Every time that the phone connects to the internet, the radio in that phone stays on (or in a standby mode) for something like 2 minutes. Those modes (on and standby) drain the battery. Another problem is that it does use data needlessly and in some countries cellular data is expensive (Canada for example).
This could be a solution if the data changes very very frequently (for example a stock's price can change many many times a day). But generally speaking method 2 is the preferred method..
2.Pushing the content to the user's phone.
Your server will send a message to the device once new data that you want to send is there (and you could also put that data in the payload of the message if it's not too much).
This means that the phone will connect only when some new data is available.
Saves battery life,and gets the information as soon as it is available!
I recommend using GCM (Google Cloud Messaging) for this purpose which is free, and simple to use. If you have no idea how to do that in Android (which is likely since you said that you are a beginner), it is explained really well in Udacity's
Advanced Android App Development. It is a free course by Udacity and Google, but the section about GCM is only about 15 minutes long.
If you know how to implement a server but don't know how to use GCM in your server (and you don't find Google's documentation helpful) do let me know..
If you don't know how to implement a server...well then it's something you will have to learn in order to get your content to your users as that's the best way.
I hope this helps! :)
Short skippable intro:
I work at a rehabilitation hospital that's a couple kilometers from where I live. The hospital pays a bus service that picks the employees up at certain fixed locations. There's this bus driver, that picks us at 7:00. The guy is FREAKISHLY PUNCTUAL. I mean, this guy has to be in the tenth of a second order. The clock turns from 6:59 to 7:00 EXACTLY when he opens the bus door. And I was thinking of recording his punctuality for like 30 days and make a nice Excel spreadsheet for him. Error propagation and everything. He might even get a raise, who knows?
I'll make a simple app to save time in milliseconds, that seems easy enough, there're like half a dozen solutions for that here in Stackoverflow.
So, to the question:
I hit a button on a widget. It gets a time in ms. It saves it on a file (.txt, .csv, whatever)
How would you estimate the mean error of an NTP synchronized Android phone? What's the most precise and exact way to save a timestamp?
Thanks in advance
First thing that comes to mind is that time is relative, in the Einstein kind of way :) So if your reference is an Android phone synchronized with NTP, what is the driver's time reference? What if synchronization or timing somehow gets off, delayed on your phone and you have the impression that he's late one day, when in fact he's precisely on time relative to his reference?
But for the sake of solving the problem i think you can start by assuming he has the same time reference with you: some place in a network. I don't know the details of Android synchronization via time protocols, but i do know i built a so called Network Synchronization API. In your case i think my Java API might be of help. It tries to make a request for the number of milliseconds since the Unix epoch and then reads the response. The feature is that it gives you a framework on which you can estimate your true time compared to the server's by trying to discard network lag.
One thing to bear in mind: the solution above makes a request to my site (a.k.a. GoDaddy servers) which is probably different than the network location Android phones sync with. Feel free to change the request location.
Second thing to bear in mind: this rabbit hole goes deep :) No measurement can be perfect. You can try to achieve human / reasonable precision but it can never be perfect (e.g. there are other unknowns: what if there's a lag in your Android CPU just as you press the button, or what if your own reaction takes a few milliseconds? The moment you press the button is not the same as the moment the doors actually open and my impression is they're at least a few millis apart)
Maybe someone here had already done this before - I'm not sure how to solve this safely...
My client want a kind of in-app-purchase for an Android application. But that's only subsidiary - my problem is: there should be a kind of "rental" system. That means someone buys i.e. an item for a certain timeframe (i.e. 10 days). The App is only online when he buys that item - so I need a safe way to let this item expire offline after 10 days. If I use the internal clock, there are to much ways to manipulate this.
Any advice how I can accomplish this (relative) safely?
Thank you,
As it is run from an "almost always connected device" you could use an external source for checking the time ( and check it each time it use the rented item or periodically if you find it inconvenient),
It is how it is mostly done, and instead of relying on timestamp it relies on certificate that should be checked against a certificate server and is harder to tamper with.