I'm using Google Maps on my app so I'd like to know a different way to do my goal. My goal is every time user joins a street it should call an api saying hey I'm in, so my question is, what's better use geofencing with this or shall I create a service that makes a call every 5 seconds to the server sending the current position?
It depends on how optimised app you want.
You can call geofencing every few secs, you can also make call to server to send current position.
You can also configure GPS to call only when user moved some distance, then for example check using geofencing if street was changed or send it to server. Some tweaks and testing will be required, to limit the calls to server and limit the battery drain
Related
I have 2 beacons. Is there possible to see in what order my app have detected the beacons??
I’m trying to detect if someone is entering/exit in a space based on the order in which beacons are detected. If this is not possible, do you know how can I do that?
When using beacon monitoring APIs (e.g. you get a didEnterRegion callback), you typically don't know which beacon triggered the entry and whether a second beacon entered again. To get this information you need to use beacon ranging APIs.
When using beacon ranging APIs (e.g. you get a didRangeBeaconsInRegion callback), the callbacks will be made in a ~1 second frequency. If you record a timestamp the very first time you get a callback for a particular beacon and then associate it with the beacon identifier, you can later tell which which beacon identifier was detected first.
If two beacons appear simultaneously within the same callback, then you need a more accurate timestamp than you can get by just looking at the time the callback was made. If you are using the Android Beacon Library version 2.17+, you can get this kind of timestamp by calling beacon.getFirstCycleDetectionTimestamp(). That method returns the number of milliseconds since 1970 that the first beacon packet was detected that led to the ranging callback.
I am working on an audio stream android app and I parsed JSON object from a server to a TextView to display 'now Playing' for the song name and artist. So when the play button is clicked, the song name playing artist is displayed to the user. The problem is that I want this automatically loaded to the app view when JSON URL link is updated from the server. I don't want the user pressing pause and play to update the view from the app. How do I go about this because I don't want the user restarting the service each time a new song isPlaying to get song information.
You can either poll server in short intervals to check if song changed or open socket connection to server to make possible server initiating communication to device.
First approach in simplest form is a very bad practice, as it puts strain on both device and server to check it often enough.
However there is different way to use it, called long polling. With this, you send request to the server, and server does not respond immediately, but holds connection open until it has something to say. After getting reply instantaneously new request is created to make sure no delay is made by it.
The best approach is opening a socket connection, but not every server and program support it.
You can try libraries like SignalR (this one is for .NET mostly, but it's the first one that came to my mind) that choose which approach is the best and takes care of holding connection, reconnecting etc.
Are you fetching this JSON metadata every time the song is played? If so, that doesn't sound like a good idea. The ideal would be to add song metadata when adding a song to the playlist, then either update it periodically (once a couple of days perhaps) and save that information into a SQLite database for later retrieval.
We're developing special devices that uses XMPP to talk to each other. A new API i am developing now, should talk to these devices too. The problem i am facing - all these devices are building little groups - for each customer we have... so we will have a chat-room for each group of devices, or, for each of our customer with his bunch of devices ;)
But now.. the api should be able to talk to every device that is connected. I don't need a real broadcast-mechanism - in the end, i will send a message only to one specific device..
But i don't want to login to each chat-room either - running a product with over 40k customers and much more devices, will end in a funny api, that is opening over 40k chat-rooms at startup... even if don't tried this yet, i can't imagine that an app like this will run well... even though we can have millions of customers in a few years.. i don't like solutions that will grow linear with the amount of customers, if you know what i mean :/
Now, basically i'm thinking of a solution, where i just can use the basic XMPPConnection to do my stuff.
MyCustomMessage msg = new MyCustomMessage();
msg.setTo("*"); // don't know what to address, i want to send it to "all"
msg.setFrom("ThatAPI"); // just a string telling that is sent from my java api ;)
msg.setEvent(event); // stuff that is coming through the parameters of the method where this code is inside
msg.setCustomStanza(data); // same here
connection.sendPacket(msg); // my try to send it to all till now..
Somewhere in the Ignite Realtime Forums i have read of one guy who "solved" it, but everything he says is "it's working now, i push my message through the sendPacket of Connection"... ok nice, my attempt of this seems not to work :(
Any better ideas/real implementations how this will work fine?
Basically i start to think that XMPP will not be the best technology to achieve something like this at all - i wish i could have a real/basic socket-implementation where something like this would be piece of cake.. But i can't choose - the third-party-system has implemented XMPP already... not enough time to change all of this... Just if you're wondering why we try this on XMPP..
You seem to have some conflicting requirements in that you want to send to all devices now, but only 1 specific device later. Are both models required at the same time, or do you plan on switching? How either is done would be different solutions.
As for your current approach, I think pubsub would make more sense than your chatroom approach, as that is oriented to generic message passing to subscribers.
You could set up a pubsub node per customer to send messages to all
of their devices.
As for a broadcast to all, you can make all devices
subscribe to a single pubsub node.
Thus you control broadcast and group messages by sending to the appropriate pubsub node.
For sending to a specific device, that is just a sendPacket to the specific entity, nothing really special there.
I wanted to learn more about the Android Services / Broadcasts, so I started a simple project, to create a battery monitoring app. It turned out pretty good, I'm using it for a few days now, but I want to add a new function: to show since when is the phone charging/discharging.
First I thought that I would create two static fields in my BoradcastReciever extension class, where I get and publish the data about the battery, one for the actual state (charging/discharging), and one for the time, when the change in state happened. This way, I could just subtract from the current time the last change, and know exactly since when is the phone charging/discharging.
But there is a problem with this solution: It won't show the correct data at first, when a user starts the app. I wouldn't make a big deal of it, but I saw that Android tracks this data somewhere, because inside my phone settings I found this information, so why take the hard way.
So my question is: is there an easy way to get from the Android system the date/time (no matter what format) of the last charging state change?
I looked at the BatteryManager reference but there are no constants named after what I seek, and which I could use, to get the information from the Intent of my receiver.
The Android OS tracks the connect/disconnect of a power source, but does not make this data accessible to apps. You have to record this all yourself, using intent filters.
The two intent filters to use are android.intent.action.ACTION_POWER_CONNECTED and android.intent.action.ACTION_POWER_DISCONNECTED; with these, you can monitor when the power source is connected and disconnected.
You can find information about this process explained incredibly clearly here. Another blog describing the process can be found here.
I have something of an abstract question regarding managing live feeds/polling on web sites.
I am creating a web app (built on Java/Spring/Hibernate) and on the user's home page I want a live feed of the latest activity from all the members of there team, and I am trying to work out the best way to handle this query on the server side.
The brute force way would be to load the current users list of team mates, and then iterate through each of his team mates, loading their latest conversations/file uploads/etc, and then merging all this activity in to a single list sorted by timestamp and returning that (lets say for sake of example that we just return the top 10 latest activity for the feed).
However, that seems very un-performant, especially as this operation would need to be done regularly (depending on the polling interval).
I have also considered making all the potential activities (conversations/status updates/uploads) as extending an Activity class and then just having a direct SQL/JPQL query in a DAO that selects all the latest activity from a set of users to be returned, but concerned that might bypass the caching and continued access to the DB would also reduce performance.
Has anyone handled this type of problem before? any one know what a good approach is?
Thanks!
This is an old one now, but here is what i did for this:
All tasks that should appear on a live wall extend Activity (this was already the case)
Created a new Notification object, the Notification had a link to the underlying Activity and a link to a user (who was being notified).
Created a pre-persist hook for Activity that created a Notification object for the Activity being persisted - it did this for every user that was interested (all users following the user that was persisting the Activity)
For the moment, Notifications are persisted/retrieved to the DB - possibly not scalable to very high volumes, but the approach I think supports moving to a Queue based system (such as LinkedIn's Kafka queue library which is designed exactly for this purpose). As it is per-user, it also provides the option to have a read/unread notification flag for significant notifications.