1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.location
;
21 import android
.app
.IntentService
;
22 import android
.content
.Intent
;
23 import android
.content
.SharedPreferences
;
24 import android
.location
.Criteria
;
25 import android
.location
.Location
;
26 import android
.location
.LocationListener
;
27 import android
.location
.LocationManager
;
28 import android
.location
.LocationProvider
;
29 import android
.os
.Bundle
;
30 import android
.preference
.PreferenceManager
;
31 import android
.util
.Log
;
32 import android
.widget
.Toast
;
34 import com
.owncloud
.android
.R
;
36 public class LocationUpdateService
extends IntentService
implements
39 public static final String TAG
= "LocationUpdateService";
41 private LocationManager mLocationManager
;
42 private LocationProvider mLocationProvider
;
43 private SharedPreferences mPreferences
;
45 public LocationUpdateService() {
50 protected void onHandleIntent(Intent intent
) {
51 mLocationManager
= (LocationManager
) getSystemService(LOCATION_SERVICE
);
52 // Determine, how we can track the device
53 Criteria criteria
= new Criteria();
54 criteria
.setAccuracy(Criteria
.ACCURACY_FINE
);
55 criteria
.setPowerRequirement(Criteria
.POWER_LOW
);
56 mLocationProvider
= mLocationManager
.getProvider(mLocationManager
57 .getBestProvider(criteria
, true
));
59 // Notify user if there is no way to track the device
60 if (mLocationProvider
== null
) {
61 String message
= String
.format(getString(R
.string
.location_no_provider
), getString(R
.string
.app_name
));
64 Toast
.LENGTH_LONG
).show();
69 // Get preferences for device tracking
70 mPreferences
= PreferenceManager
.getDefaultSharedPreferences(this);
71 boolean trackDevice
= mPreferences
.getBoolean("enable_devicetracking",
73 int updateIntervall
= Integer
.parseInt(mPreferences
.getString(
74 "devicetracking_update_intervall", "30")) * 60 * 1000;
75 int distanceBetweenLocationChecks
= 50;
77 // If we do shall track the device -> Stop
79 Log
.d(TAG
, "Devicetracking is disabled");
84 mLocationManager
.requestLocationUpdates(mLocationProvider
.getName(),
85 updateIntervall
, distanceBetweenLocationChecks
, this);
89 public void onLocationChanged(Location location
) {
90 Log
.d(TAG
, "Location changed: " + location
);
95 public void onProviderDisabled(String arg0
) {
96 // TODO Auto-generated method stub
101 public void onProviderEnabled(String arg0
) {
102 // TODO Auto-generated method stub
107 public void onStatusChanged(String arg0
, int arg1
, Bundle arg2
) {
108 // TODO Auto-generated method stub