Detecting when an Android device is in a certain location - android

What's the best way of detecting when an Android device is in a certain location? I'm creating a device admin app that enforces certain policies when the device is in a certain premise, e.g. a certain office building, and in order to enforce the policies, I need to know where the device is, and the Device Administrator API does not have any geo-location/geo-fence APIs.
I can think of a few methods, but none are foolproof:
Poll fine location (Wifi/GPS) - dependent on whether user has Wifi/GPS on. Impossible to enforce. Also, GPS doesn't work indoors and drains battery significantly.
Poll course location(cell tower) - more reliable, but inaccurate.
Place wifi routers around premises and detect when they are near - dependent of whether user has Wifi on.
What's the best way of detecting a device's location?

The only thing that meet your requirements are iBeacons or comparable devices.
That are blue tooth low energy beacons. Which are mounted on walls in the building.
They emit a beacon id and the distance to that device. You have to manage which beacon id is mounted at which place.
This technique was developed by Apple, so look how you can use that within android.
Outdoors GPS works best, you have to live with battery drain.
Cell Tower locationing you better forget, that has only about 1000m acuracy. Wlan locationing, too is of limited use.

Related

I want to pair my Android device to a beacon or other BTLE device, and if I move my device too far away from that beacon, lock the screen or send msg

I have Android devices mounted on vehicles in a manufacturing facility, and I'd like to deter people from removing them from one vehicle and moving it to another vehicle, but also still allow it (long story, but instead of physically locking the device to the vehicle with a cable or other device I'm looking to make it more inconvenient than impossible...). I was thinking if I mounted a Bluetooth low energy BTLE device or beacon of some sort to the vehicle in some inaccessible location, then pair my Android device to that beacon, my device would be allowed to work as long as it 'saw' that beacon. If someone were to move the device to another vehicle, it wouldn't see the beacon and would have to be 'paired' to the new vehicle, supplying a reason why it had to be moved, etc. Is BTLE/beacon the right technology for this or is there something better?
Such a solution is possible with BLE beacons but has some implementation challenges. I have seen beacons used successfully in similar use cases like automatic workstation locking, contact tracing, virtual tethering of demo phones, and convention audience counting.
BLE has a range of about 30-40 meters, longer with clear line of sight. If the Android devices is moved from one vehicle to another that are within 40 meters of each other, the original beacon will probably still be visible.
You may be able to address the above issue with a "closest beacon" strategy, meaning that you consider whatever is seen as closest beacon above a certain signal threshold to be the vehicle the device is on or in.
If you use a battery-powered beacon, you can mount it anywhere, but battery life will typically be limited to a year or less.
A plugged-in beacon will never run out of power, but requires a USB supply, and AC outlet, or a DC supply like a car cigarette lighter port. This limits where you can hide it.
As you mention, there are other solutions aside from BLE like physical tether. But it is not inappropriate to consider BLE as it is widely used for similar proximity measurement applications.

Android - Detect if other users of my app are nearby

I'm working on an Android app that needs to detect if other users of the app are close to each other (lets say within the same room or Bluetooth range). The app needs to be able to detect this without any user interaction.
Geolocation is not an option as this is too inaccurate indoors.
The app runs only on company owned phones that stay on company ground, privacy is not a concern.
All devices are always connected to the same wifi network and BT is always enabled.
My idea is to detect if users are within a close distance of eachother by periodically Bluetooth scanning and checking the results against a list of MAC adresses that contain all the devices that have the app installed.
The MAC adresses of all devices are send to a server, the devices then grab this list of mac adresses from the server to compare to the results of a BT scan.
Problem is, BT and Google's seem to use Advertisement / Discovery patterns where one device acts as the server and one device acts as the client. For this to work properly i feel like the devices need to always be discoverable.
Will an implementation based on Google's Nearby or BT work for my needs ?
Is it possible to detect the presence of a nearby device without it being discoverable ?
As battery life is a concern (need to be able to do this for atleast 8 hours a day) is BLE an option?
You can almost certainly handle 8 hours a day if the phones aren't really used for much else. There are a lot of variables, however.
Many older phones require a different type of scanning using infinite scanner restarts in order to properly report "seeing" a peripheral. This can dramatically decrease battery life.
If the phones are running Marshmallow or later, they have a doze mode which interrupts scanning. This can be circumvented using an AlarmManager, JobService/Dispatcher, or WorkManager. This can dramatically decrease battery life.
If the phones are running Oreo or later, they require a foreground service (persistent notification) in order to prevent the app from being automatically killed by the OS to save battery. The app should also be whitelisted from battery optimization because even with the foreground service, the app will still be killed off by the OS.
Finally, scanning and broadcasting and using location services is pretty expensive battery-wise. If you're attempting to cluster phones and guess their position based upon what other phones are nearby, at some level you'll still need the location data off of the phones to figure out where they're at.
You're much better off just scanning. You could carpet your company property with beacons, where each individual beacon's location is recorded. When the phone "enters a region" (comes within range of a beacon), it should send something to your api reporting which beacon it just found. This will tell you what room/area it's in.
Another less flashy (and potentially less accurate) way to track everything would be via the IP addresses of the wireless access points they're connected to. Use a WorkManager to periodically update an api with some unique ID for the phone and the IP address of the AP. Your IT department should know the locations of each of them. This way you get reasonably good tracking and virtually no battery drain.

API to detect distance between Wear watch & Android phone?

In my application, we want to warn the user when he is at distance from Phone or watch.
We are scanning nearest nodes using APIs of wear OS.
Is there any way I can detect the distance between two such nodes?
Getting geolocation of both & calculate distance using formula is one possible way.
But aren't the APIs on wear OS has something which can detect distance using Bluetooth range or signal strength?
The best that's directly supported by the platform is the Node API's isNearby method, but that essentially just returns true iff the phone-watch connection is over Bluetooth rather than cellular or wifi. It doesn't give you anything resembling a real distance number.
Beyond that, you'd have to roll your own solution using GPS on both devices, as you mention. But that has a lot of downsides: complexity, reliability, and battery use are ones that immediately occur to me. Someday, you'll be able to get this kind of accuracy from the fused location provider using wifi, but probably not for some years.

How can I detect if an Android device is indoor/outdoor?

I'm developing an app which fuses location from various providers, hoping it will give a more accurate location than if I simply used the Google API. However, the choice of providers would depend on the phone being indoor or outdoor (Network vs GPS, for example).
What is the best way to detect if the device is indoor or outdoor? My first thought would be using the Light sensor, and maybe cell signal strength and WiFi (if there are WiFi networks near, it's likely the device is indoor), but I don't know which weight/confidence I should attribute to these sensors.
Edit: this is for my masters thesis, in which the goal is to get the location from the different providers (GPS, Network and Passive) in the Android API, and fuse them with a formula. Depending on whether the phone is indoor or outdoor, the several locations would have different weights. There would also be parameters like if battery life is priority or not (I haven't developed this formula yet).
Just subscribe to both providers and use location.getProvider() and location.getAccuracy() when new location arrives--to check if it's more/less accurate then previous.
I'd say your best bet is the GPS signal itself, because GPS rarely penetrates buildings.
In built up areas, you'll encompass WiFi networks all over the shop.

GPS clarification

I'd just like to ask for some clarifications regarding the GPS functionalities of android phones. When an application activates the GPS of a phone, will the phone need to be on a data plan or should activate the data traffic ( Settings > Wireless & Network settings > Mobile Networks > Data Traffic) for the GPS to get the phone's coordinates?
From Wikipdeia
The Global Positioning System (GPS) is a space-based satellite
navigation system that provides location and time information in all
weather, anywhere on or near the Earth, where there is an unobstructed
line of sight to four or more GPS satellites. It is maintained by the
United States government and is freely accessible to anyone with a GPS
receiver.
If you talk specifically about GPS then it's nothing to do with the data plan or even with your service provider. GPS is totally independent of it. Think of a stand alone GPS receiver device e.g. Garmin GPS 10. It just connects to your laptop through Bluetooth (some with USB cable) and start sending GPS data to it. These devices normally output GPS data in NMEA format. Modern phones includes same sort GPS receiver circuit integrated in them. The thing different here is that these phones consumes GPS data for internally available rather than directly outputting in raw form. That's how you get GPS location information in iPhone and Android smart phones. On the other hand think of GPS navigation devices we use in our cars e.g. Garmin nuvi. It shows the location of car on the integrated maps. There is no sim card in it. Same is with GPS fitness watches.
A good question here is How GPS calculates the location? Best explanation I found is on HowStuffWorks. It's very easy and very well explained. Apart form GPS there are other positioning systems in the world, though GPS is oldest and most widely used. After GPS from US, there is GLONASS from Russia. Some phones support GLONASS too e.g. iPhone 4S and Samsung Galaxy S III. Well there is nothing to worry for developers though. These phones internally use GPS and GLONASS to have high positional accuracy and gives the location in same way.
Other positioning systems includes Compass from China and Galileo. These are under development at the moment. For complete list check this Wikipedia article.
Edit: Location can be also be determined by mobile networks and wifi networks. For example Google Latitude tells your approximate location if you are connected with wifi and even you don't have GPS device connected. In case of location determination by mobile networks, the service provider may charge for location. Normally locations determined by mobile and wifi networks are not very accurate but location can be determined indoors which is a very big problem of GPS location calculation.
Hopefully it will help how things are working.
Cheers! :)
Atleast in India I can access use the GPS whenever I can see the sky, no data plan is required for me.
I haven't tried it on Android but it should be possible to get GPS co-ordinates without a data plan. My iPhone gets GPS locations even when out of reception, I can't see why android would be any different.

Categories

Resources