0

I would like to detect a user's home place, and whenever the user leaves and arrives home, do something in my application. I was searching for so long for a questing with this specific problem, but all the 'home' related questions are to the home button of the device.

I have few options, as far as i can tell :

  1. Ask the user to give his house address
  2. Use FenceApi or implement my own LocationListener and check every location received, and see if it's within few meters radius from my house.

Obviously, asking the user for his house isn't really intelligent. Anyone knows how can i detect his house without asking for it ? I was thinking of storing locations, and mapping the hits of the locations.

This is more of an abstract question, so i didn't attach any code.

Community
  • 1
  • 1
JenniferH
  • 95
  • 6
  • https://developers.google.com/awareness/ – Marcin Orlowski Sep 04 '16 at 14:39
  • You obviously didn't read my question, i said i can use FenceApi, which connects to AwarenessApi. – JenniferH Sep 04 '16 at 14:50
  • If you need to do it as a background service and with LocationListener, it will be highly power consuming. Can you afford to do it as a foreground service? As like when user opens the app, the app will tell him that he is at home or not. – Sudip Podder Sep 04 '16 at 16:08

2 Answers2

1

You can ask user to add his home's WiFi name, register BroadcastReceiver for CONNECTIVITY_CHANGE in which check the WiFi available and it's name

But in Android 7.0 CONNECTIVITY_CHANGE broadcast not working, if app isn't active

Community
  • 1
  • 1
Dmytro Rostopira
  • 10,588
  • 4
  • 64
  • 86
1

You can use Neura sdk in order to detect when user arrives and leaves home, which fits your needs exactly.

This is their Developers guide for Android.

Check out this samples on git :

  1. HomeAndAway : receiving events when user arrives/leaves home, and displaying it in the ui.
  2. LeftHomeWifiDisabled : disabling wifi when user leaves home (in order to save battery) and enabling wifi when user arrives home. There's a full explanation for each project and how to make it 'your own'.
Dus
  • 4,052
  • 5
  • 30
  • 49
  • I looked at the git projects, there's a screen there for declaring a 'home' for the current user. But, i want it to be 'smarter' then requesting the user to put his/her home. – JenniferH Sep 04 '16 at 15:54
  • You don't have to display the screen for declaring 'home'. The Neura sdk will find your home within few days (for me, it was 5 days). If you don't want to wait x days for detecting your home, you can display the picker for setting your home, but, you don't have to, you can just wait, and after your home is found, you'll receive the events for 'arrived home' and 'left home' – Dus Sep 04 '16 at 15:56
  • Ok, so i'll just use the git project you've provided, but without calling mNeuraApiClient.getMissingDataForEvent(...) method. I'd rather wait for the detection of home to be in the background, and can handle few days of not having the home set yet. – JenniferH Sep 04 '16 at 16:00