質問編集履歴
10
ログを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -208,4 +208,11 @@
|
|
208
208
|
}
|
209
209
|
|
210
210
|
|
211
|
+
```
|
212
|
+
```java
|
213
|
+
07-30 03:21:01.964 5676-5676/com.google.android.exoplayer2.demo D/onCreate(): 呼ばれた
|
214
|
+
07-30 03:21:01.965 5676-5676/com.google.android.exoplayer2.demo D/onStartCommand: 呼ばれた
|
215
|
+
07-30 03:21:01.965 5676-5676/com.google.android.exoplayer2.demo D/StartLocation: 呼ばれた
|
216
|
+
07-30 03:21:01.965 5676-5676/com.google.android.exoplayer2.demo V/initLocationService(): 呼ばれた
|
217
|
+
07-30 03:21:01.975 5676-5676/com.google.android.exoplayer2.demo D/StartLocation: 呼ぶ
|
211
218
|
```
|
9
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -137,13 +137,13 @@
|
|
137
137
|
throw new UnsupportedOperationException("Not yet implemented");
|
138
138
|
}
|
139
139
|
|
140
|
-
private void
|
140
|
+
private void startLocation() {
|
141
141
|
|
142
|
-
Log.d("
|
142
|
+
Log.d("StartLocation","呼ばれた");
|
143
143
|
initLocationService();
|
144
144
|
}
|
145
145
|
|
146
|
-
private void
|
146
|
+
private void stopLocation() {
|
147
147
|
Log.d("stopLocation","呼ばれた");
|
148
148
|
//firebase.auth().signOut();これでログアウトはできるが、ログアウトはしない
|
149
149
|
database.goOffline();
|
@@ -157,11 +157,11 @@
|
|
157
157
|
String check =intent.getStringExtra("start/stop");
|
158
158
|
|
159
159
|
if(check.equals("start")){
|
160
|
-
|
160
|
+
startLocation();
|
161
|
-
Log.d("
|
161
|
+
Log.d("StartLocation","呼ぶ");
|
162
162
|
}else if(check.equals("stop")){
|
163
|
-
|
163
|
+
stopLocation();
|
164
|
-
Log.d("
|
164
|
+
Log.d("StopLocation","呼ぶ");
|
165
165
|
}
|
166
166
|
|
167
167
|
return super.onStartCommand(intent, flags, startId);
|
@@ -202,9 +202,10 @@
|
|
202
202
|
public void onCancelled(DatabaseError databaseError) {
|
203
203
|
Log.v("onCancelled()","呼ばれた");
|
204
204
|
}
|
205
|
-
};
|
205
|
+
};
|
206
206
|
ref.addChildEventListener(childEventListener);
|
207
207
|
}
|
208
208
|
}
|
209
209
|
|
210
|
+
|
210
211
|
```
|
8
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -45,8 +45,8 @@
|
|
45
45
|
Log.d("onCreate()","呼ばれた");
|
46
46
|
}
|
47
47
|
|
48
|
-
|
49
48
|
|
49
|
+
|
50
50
|
public GpsService() {
|
51
51
|
}
|
52
52
|
|
@@ -139,12 +139,12 @@
|
|
139
139
|
|
140
140
|
private void startFusedLocation() {
|
141
141
|
|
142
|
-
Log.d("
|
142
|
+
Log.d("onStartLocation","呼ばれた");
|
143
143
|
initLocationService();
|
144
144
|
}
|
145
145
|
|
146
146
|
private void stopFusedLocation() {
|
147
|
-
Log.d("
|
147
|
+
Log.d("stopLocation","呼ばれた");
|
148
148
|
//firebase.auth().signOut();これでログアウトはできるが、ログアウトはしない
|
149
149
|
database.goOffline();
|
150
150
|
}
|
@@ -158,10 +158,10 @@
|
|
158
158
|
|
159
159
|
if(check.equals("start")){
|
160
160
|
startFusedLocation();
|
161
|
-
Log.d("
|
161
|
+
Log.d("onStartLocation","呼ぶ");
|
162
162
|
}else if(check.equals("stop")){
|
163
163
|
stopFusedLocation();
|
164
|
-
Log.d("
|
164
|
+
Log.d("onStopLocation","呼ぶ");
|
165
165
|
}
|
166
166
|
|
167
167
|
return super.onStartCommand(intent, flags, startId);
|
@@ -202,10 +202,9 @@
|
|
202
202
|
public void onCancelled(DatabaseError databaseError) {
|
203
203
|
Log.v("onCancelled()","呼ばれた");
|
204
204
|
}
|
205
|
-
};
|
205
|
+
};
|
206
206
|
ref.addChildEventListener(childEventListener);
|
207
207
|
}
|
208
208
|
}
|
209
209
|
|
210
|
-
|
211
210
|
```
|
7
コードの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,17 +12,12 @@
|
|
12
12
|
import android.location.LocationManager;
|
13
13
|
import android.os.Binder;
|
14
14
|
import android.os.IBinder;
|
15
|
-
//import com.google.android.gms.location.LocationListener;
|
16
15
|
import android.location.LocationListener;
|
17
|
-
import com.google.android.gms.common.api.GoogleApiClient;
|
18
16
|
import android.content.pm.PackageManager;
|
19
17
|
import android.location.Location;
|
20
18
|
import android.support.v4.app.ActivityCompat;
|
21
19
|
import android.os.Bundle;
|
22
20
|
import android.util.Log;
|
23
|
-
import android.widget.TextView;
|
24
|
-
import com.google.android.gms.location.FusedLocationProviderApi;
|
25
|
-
import com.google.android.gms.location.LocationRequest;
|
26
21
|
import com.google.android.gms.common.ConnectionResult;
|
27
22
|
import com.google.firebase.database.ChildEventListener;
|
28
23
|
import com.google.firebase.database.DataSnapshot;
|
@@ -31,9 +26,7 @@
|
|
31
26
|
import com.google.firebase.database.FirebaseDatabase;
|
32
27
|
import com.google.firebase.auth.FirebaseAuth;
|
33
28
|
|
34
|
-
public class GpsService extends Service implements
|
29
|
+
public class GpsService extends Service implements LocationListener{
|
35
|
-
GoogleApiClient.ConnectionCallbacks,
|
36
|
-
GoogleApiClient.OnConnectionFailedListener,LocationListener{
|
37
30
|
|
38
31
|
private boolean mResolvingError = false;
|
39
32
|
final FirebaseDatabase database = FirebaseDatabase.getInstance();
|
@@ -52,34 +45,8 @@
|
|
52
45
|
Log.d("onCreate()","呼ばれた");
|
53
46
|
}
|
54
47
|
|
48
|
+
|
55
49
|
|
56
|
-
@Override
|
57
|
-
public void onConnected(Bundle bundle) {
|
58
|
-
Log.d("onConnected()","呼ばれた");
|
59
|
-
}
|
60
|
-
|
61
|
-
@Override
|
62
|
-
public void onConnectionSuspended(int i) {
|
63
|
-
Log.d("onConnectionSuspended()","");
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
@Override
|
68
|
-
public void onConnectionFailed(ConnectionResult connectionResult) {
|
69
|
-
Log.v("onConnectionFailed()","呼ばれた");
|
70
|
-
|
71
|
-
if (mResolvingError) {
|
72
|
-
// Already attempting to resolve an error.
|
73
|
-
Log.d("", "Already attempting to resolve an error");
|
74
|
-
|
75
|
-
return;
|
76
|
-
} else if (connectionResult.hasResolution()) {
|
77
|
-
|
78
|
-
} else {
|
79
|
-
mResolvingError = true;
|
80
|
-
}
|
81
|
-
}
|
82
|
-
|
83
50
|
public GpsService() {
|
84
51
|
}
|
85
52
|
|
@@ -149,11 +116,11 @@
|
|
149
116
|
//sensorEventListener = new GpsLocationListener(sensorValueTextView);
|
150
117
|
|
151
118
|
|
152
|
-
public class LocationServiceBinder extends Binder {
|
119
|
+
// public class LocationServiceBinder extends Binder {
|
153
|
-
public com.google.android.exoplayer2.demo.GpsService getService() {
|
120
|
+
// public com.google.android.exoplayer2.demo.GpsService getService() {
|
154
|
-
return com.google.android.exoplayer2.demo.GpsService.this;
|
121
|
+
// return com.google.android.exoplayer2.demo.GpsService.this;
|
122
|
+
// }
|
155
|
-
|
123
|
+
// }
|
156
|
-
}
|
157
124
|
protected void refreshGeoLocation(Location location){
|
158
125
|
Log.v("refreshGeoLocation","呼ばれた");
|
159
126
|
String user = FirebaseAuth.getInstance().getCurrentUser().getUid();
|
6
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
Activityでは、このようなコードで位置情報を取得できていたのですが、Serviceでは、エラーが出ます。エラーが出ます。アドバイスをいただけないでしょうか?
|
4
4
|
|
5
|
+
|
5
6
|
```java
|
6
7
|
package com.google.android.exoplayer2.demo;
|
7
8
|
|
@@ -36,6 +37,7 @@
|
|
36
37
|
|
37
38
|
private boolean mResolvingError = false;
|
38
39
|
final FirebaseDatabase database = FirebaseDatabase.getInstance();
|
40
|
+
private LocationListener sensorEventListener; // onPause()
|
39
41
|
|
40
42
|
public class GpsServiceBinder extends Binder {
|
41
43
|
public GpsService getService() {
|
@@ -50,7 +52,7 @@
|
|
50
52
|
Log.d("onCreate()","呼ばれた");
|
51
53
|
}
|
52
54
|
|
53
|
-
|
55
|
+
|
54
56
|
@Override
|
55
57
|
public void onConnected(Bundle bundle) {
|
56
58
|
Log.d("onConnected()","呼ばれた");
|
@@ -77,7 +79,7 @@
|
|
77
79
|
mResolvingError = true;
|
78
80
|
}
|
79
81
|
}
|
80
|
-
|
82
|
+
|
81
83
|
public GpsService() {
|
82
84
|
}
|
83
85
|
|
@@ -86,18 +88,19 @@
|
|
86
88
|
// protected void onPause(){
|
87
89
|
// super.onPause();
|
88
90
|
// locationManager.removeUpdates(this);
|
91
|
+
// mLocationManager.removeUpdates(listener);
|
89
92
|
// }
|
90
|
-
|
91
|
-
protected void initLocationService(){
|
92
|
-
Log.v("initLocationService()","呼ばれた");
|
93
93
|
|
94
|
+
protected void initLocationService() {
|
95
|
+
Log.v("initLocationService()", "呼ばれた");
|
96
|
+
|
94
97
|
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
95
98
|
return;
|
96
99
|
}
|
97
100
|
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
98
101
|
return;
|
99
102
|
}
|
100
|
-
|
103
|
+
|
101
104
|
Criteria criteria = new Criteria();
|
102
105
|
criteria.setAccuracy(Criteria.ACCURACY_FINE); //setAccuracyは内部では、https://stackoverflow.com/a/17874592/1709287の用にHorizontalAccuracyの設定に変換されている。
|
103
106
|
criteria.setPowerRequirement(Criteria.POWER_HIGH);
|
@@ -113,9 +116,39 @@
|
|
113
116
|
|
114
117
|
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
115
118
|
String bestProvider = locationManager.getBestProvider(criteria, true);
|
116
|
-
locationManager.requestLocationUpdates(bestProvider,6000,1,this);
|
119
|
+
locationManager.requestLocationUpdates(bestProvider, 6000, 1, this);
|
117
120
|
}
|
118
121
|
|
122
|
+
@Override
|
123
|
+
public void onLocationChanged(Location location) {
|
124
|
+
|
125
|
+
Log.v("onLocationChanged", "呼ばれた");
|
126
|
+
refreshGeoLocation(location);
|
127
|
+
}
|
128
|
+
|
129
|
+
//LocationListenerのメソッド
|
130
|
+
@Override
|
131
|
+
public void onStatusChanged(String provider, int status, Bundle extras) {
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
@Override
|
136
|
+
public void onProviderEnabled(String provider) {
|
137
|
+
|
138
|
+
}
|
139
|
+
|
140
|
+
@Override
|
141
|
+
public void onProviderDisabled(String provider) {
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
//ここまで
|
147
|
+
|
148
|
+
// 位置情報のリスナーを取得して登録する
|
149
|
+
//sensorEventListener = new GpsLocationListener(sensorValueTextView);
|
150
|
+
|
151
|
+
|
119
152
|
public class LocationServiceBinder extends Binder {
|
120
153
|
public com.google.android.exoplayer2.demo.GpsService getService() {
|
121
154
|
return com.google.android.exoplayer2.demo.GpsService.this;
|
@@ -130,7 +163,7 @@
|
|
130
163
|
latitudeRef.setValue(location.getLatitude());
|
131
164
|
longitudeRef.setValue(location.getLongitude());
|
132
165
|
}
|
133
|
-
|
166
|
+
|
134
167
|
@Override
|
135
168
|
public IBinder onBind(Intent intent) {
|
136
169
|
Log.v("onBind","呼ばれた");
|
@@ -168,30 +201,6 @@
|
|
168
201
|
}
|
169
202
|
|
170
203
|
@Override
|
171
|
-
public void onLocationChanged (Location location){
|
172
|
-
|
173
|
-
Log.v("onLocationChanged","呼ばれた");
|
174
|
-
refreshGeoLocation(location);
|
175
|
-
}
|
176
|
-
|
177
|
-
//LocationListenerのメソッド
|
178
|
-
@Override
|
179
|
-
public void onStatusChanged(String provider, int status, Bundle extras) {
|
180
|
-
|
181
|
-
}
|
182
|
-
|
183
|
-
@Override
|
184
|
-
public void onProviderEnabled(String provider) {
|
185
|
-
|
186
|
-
}
|
187
|
-
|
188
|
-
@Override
|
189
|
-
public void onProviderDisabled(String provider) {
|
190
|
-
|
191
|
-
}
|
192
|
-
//ここまで
|
193
|
-
|
194
|
-
@Override
|
195
204
|
public void onDestroy() {
|
196
205
|
super.onDestroy();
|
197
206
|
}
|
@@ -231,4 +240,5 @@
|
|
231
240
|
}
|
232
241
|
}
|
233
242
|
|
243
|
+
|
234
244
|
```
|
5
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -50,8 +50,7 @@
|
|
50
50
|
Log.d("onCreate()","呼ばれた");
|
51
51
|
}
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
|
55
54
|
@Override
|
56
55
|
public void onConnected(Bundle bundle) {
|
57
56
|
Log.d("onConnected()","呼ばれた");
|
@@ -78,8 +77,7 @@
|
|
78
77
|
mResolvingError = true;
|
79
78
|
}
|
80
79
|
}
|
81
|
-
|
82
|
-
|
80
|
+
|
83
81
|
public GpsService() {
|
84
82
|
}
|
85
83
|
|
@@ -89,8 +87,7 @@
|
|
89
87
|
// super.onPause();
|
90
88
|
// locationManager.removeUpdates(this);
|
91
89
|
// }
|
92
|
-
|
93
|
-
|
90
|
+
|
94
91
|
protected void initLocationService(){
|
95
92
|
Log.v("initLocationService()","呼ばれた");
|
96
93
|
|
@@ -100,8 +97,7 @@
|
|
100
97
|
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
101
98
|
return;
|
102
99
|
}
|
103
|
-
|
104
|
-
|
100
|
+
|
105
101
|
Criteria criteria = new Criteria();
|
106
102
|
criteria.setAccuracy(Criteria.ACCURACY_FINE); //setAccuracyは内部では、https://stackoverflow.com/a/17874592/1709287の用にHorizontalAccuracyの設定に変換されている。
|
107
103
|
criteria.setPowerRequirement(Criteria.POWER_HIGH);
|
@@ -117,28 +113,16 @@
|
|
117
113
|
|
118
114
|
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
119
115
|
String bestProvider = locationManager.getBestProvider(criteria, true);
|
120
|
-
|
121
|
-
|
122
116
|
locationManager.requestLocationUpdates(bestProvider,6000,1,this);
|
123
|
-
|
124
|
-
|
125
117
|
}
|
126
|
-
/////////////////////////////////////////////////多分いらないやつ
|
127
118
|
|
128
|
-
|
129
|
-
|
130
119
|
public class LocationServiceBinder extends Binder {
|
131
120
|
public com.google.android.exoplayer2.demo.GpsService getService() {
|
132
121
|
return com.google.android.exoplayer2.demo.GpsService.this;
|
133
122
|
}
|
134
123
|
}
|
135
|
-
|
136
|
-
|
137
124
|
protected void refreshGeoLocation(Location location){
|
138
|
-
|
139
125
|
Log.v("refreshGeoLocation","呼ばれた");
|
140
|
-
|
141
|
-
|
142
126
|
String user = FirebaseAuth.getInstance().getCurrentUser().getUid();
|
143
127
|
DatabaseReference ref = database.getReference().child("users").child(user);
|
144
128
|
DatabaseReference latitudeRef = ref.child("latitude");
|
@@ -146,8 +130,7 @@
|
|
146
130
|
latitudeRef.setValue(location.getLatitude());
|
147
131
|
longitudeRef.setValue(location.getLongitude());
|
148
132
|
}
|
149
|
-
|
150
|
-
|
133
|
+
|
151
134
|
@Override
|
152
135
|
public IBinder onBind(Intent intent) {
|
153
136
|
Log.v("onBind","呼ばれた");
|
@@ -189,8 +172,6 @@
|
|
189
172
|
|
190
173
|
Log.v("onLocationChanged","呼ばれた");
|
191
174
|
refreshGeoLocation(location);
|
192
|
-
|
193
|
-
|
194
175
|
}
|
195
176
|
|
196
177
|
//LocationListenerのメソッド
|
@@ -209,8 +190,7 @@
|
|
209
190
|
|
210
191
|
}
|
211
192
|
//ここまで
|
212
|
-
|
213
|
-
|
193
|
+
|
214
194
|
@Override
|
215
195
|
public void onDestroy() {
|
216
196
|
super.onDestroy();
|
@@ -249,8 +229,6 @@
|
|
249
229
|
};
|
250
230
|
ref.addChildEventListener(childEventListener);
|
251
231
|
}
|
252
|
-
|
253
|
-
|
254
232
|
}
|
255
233
|
|
256
234
|
```
|
4
コードの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,22 +3,96 @@
|
|
3
3
|
Activityでは、このようなコードで位置情報を取得できていたのですが、Serviceでは、エラーが出ます。エラーが出ます。アドバイスをいただけないでしょうか?
|
4
4
|
|
5
5
|
```java
|
6
|
-
|
6
|
+
package com.google.android.exoplayer2.demo;
|
7
7
|
|
8
|
+
import android.app.Service;
|
9
|
+
import android.content.Intent;
|
10
|
+
import android.location.Criteria;
|
11
|
+
import android.location.LocationManager;
|
12
|
+
import android.os.Binder;
|
13
|
+
import android.os.IBinder;
|
14
|
+
//import com.google.android.gms.location.LocationListener;
|
15
|
+
import android.location.LocationListener;
|
16
|
+
import com.google.android.gms.common.api.GoogleApiClient;
|
17
|
+
import android.content.pm.PackageManager;
|
18
|
+
import android.location.Location;
|
19
|
+
import android.support.v4.app.ActivityCompat;
|
20
|
+
import android.os.Bundle;
|
21
|
+
import android.util.Log;
|
22
|
+
import android.widget.TextView;
|
8
|
-
|
23
|
+
import com.google.android.gms.location.FusedLocationProviderApi;
|
24
|
+
import com.google.android.gms.location.LocationRequest;
|
25
|
+
import com.google.android.gms.common.ConnectionResult;
|
26
|
+
import com.google.firebase.database.ChildEventListener;
|
27
|
+
import com.google.firebase.database.DataSnapshot;
|
28
|
+
import com.google.firebase.database.DatabaseError;
|
29
|
+
import com.google.firebase.database.DatabaseReference;
|
30
|
+
import com.google.firebase.database.FirebaseDatabase;
|
31
|
+
import com.google.firebase.auth.FirebaseAuth;
|
9
32
|
|
10
|
-
//このようなエラーが出ます。
|
11
|
-
Error:(160, 24) エラー: requestLocationUpdatesに適切なメソッドが見つかりません(String,int,int,GpsService)
|
12
|
-
メソッド LocationManager.requestLocationUpdates(String,long,float,LocationListener)は使用できません
|
13
|
-
|
33
|
+
public class GpsService extends Service implements
|
14
|
-
|
34
|
+
GoogleApiClient.ConnectionCallbacks,
|
15
|
-
|
35
|
+
GoogleApiClient.OnConnectionFailedListener,LocationListener{
|
16
36
|
|
37
|
+
private boolean mResolvingError = false;
|
38
|
+
final FirebaseDatabase database = FirebaseDatabase.getInstance();
|
17
39
|
|
40
|
+
public class GpsServiceBinder extends Binder {
|
41
|
+
public GpsService getService() {
|
18
|
-
|
42
|
+
return GpsService.this;
|
19
|
-
|
43
|
+
}
|
44
|
+
}
|
20
45
|
|
46
|
+
@Override
|
47
|
+
public void onCreate() {
|
48
|
+
super.onCreate();
|
49
|
+
|
50
|
+
Log.d("onCreate()","呼ばれた");
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
@Override
|
56
|
+
public void onConnected(Bundle bundle) {
|
57
|
+
Log.d("onConnected()","呼ばれた");
|
58
|
+
}
|
59
|
+
|
60
|
+
@Override
|
61
|
+
public void onConnectionSuspended(int i) {
|
62
|
+
Log.d("onConnectionSuspended()","");
|
63
|
+
|
64
|
+
}
|
65
|
+
|
66
|
+
@Override
|
67
|
+
public void onConnectionFailed(ConnectionResult connectionResult) {
|
68
|
+
Log.v("onConnectionFailed()","呼ばれた");
|
69
|
+
|
70
|
+
if (mResolvingError) {
|
71
|
+
// Already attempting to resolve an error.
|
72
|
+
Log.d("", "Already attempting to resolve an error");
|
73
|
+
|
74
|
+
return;
|
75
|
+
} else if (connectionResult.hasResolution()) {
|
76
|
+
|
77
|
+
} else {
|
78
|
+
mResolvingError = true;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
public GpsService() {
|
84
|
+
}
|
85
|
+
|
86
|
+
//serviceだからいらないかも removeupdatesは必要
|
87
|
+
// @Override
|
88
|
+
// protected void onPause(){
|
89
|
+
// super.onPause();
|
90
|
+
// locationManager.removeUpdates(this);
|
91
|
+
// }
|
92
|
+
|
93
|
+
|
21
94
|
protected void initLocationService(){
|
95
|
+
Log.v("initLocationService()","呼ばれた");
|
22
96
|
|
23
97
|
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
24
98
|
return;
|
@@ -35,23 +109,92 @@
|
|
35
109
|
criteria.setSpeedRequired(true);
|
36
110
|
criteria.setCostAllowed(true);
|
37
111
|
criteria.setBearingRequired(false);
|
38
|
-
|
39
|
-
|
40
112
|
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
|
41
113
|
criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
|
42
114
|
|
43
|
-
Integer gpsFreqInMillis = 5000;
|
44
|
-
|
115
|
+
// locationManager.registerGnssStatusCallback()
|
116
|
+
// locationManager.requestLocationUpdates(gpsFreqInMillis, gpsFreqInDistance, criteria, this, null);
|
45
117
|
|
46
|
-
|
47
118
|
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
48
|
-
bestProvider =
|
119
|
+
String bestProvider = locationManager.getBestProvider(criteria, true);
|
49
120
|
|
121
|
+
|
50
122
|
locationManager.requestLocationUpdates(bestProvider,6000,1,this);
|
123
|
+
|
124
|
+
|
51
125
|
}
|
126
|
+
/////////////////////////////////////////////////多分いらないやつ
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
public class LocationServiceBinder extends Binder {
|
131
|
+
public com.google.android.exoplayer2.demo.GpsService getService() {
|
132
|
+
return com.google.android.exoplayer2.demo.GpsService.this;
|
52
|
-
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
protected void refreshGeoLocation(Location location){
|
138
|
+
|
139
|
+
Log.v("refreshGeoLocation","呼ばれた");
|
140
|
+
|
141
|
+
|
142
|
+
String user = FirebaseAuth.getInstance().getCurrentUser().getUid();
|
143
|
+
DatabaseReference ref = database.getReference().child("users").child(user);
|
144
|
+
DatabaseReference latitudeRef = ref.child("latitude");
|
145
|
+
DatabaseReference longitudeRef = ref.child("longitude");
|
53
|
-
|
146
|
+
latitudeRef.setValue(location.getLatitude());
|
147
|
+
longitudeRef.setValue(location.getLongitude());
|
148
|
+
}
|
149
|
+
|
150
|
+
|
54
|
-
|
151
|
+
@Override
|
152
|
+
public IBinder onBind(Intent intent) {
|
153
|
+
Log.v("onBind","呼ばれた");
|
154
|
+
throw new UnsupportedOperationException("Not yet implemented");
|
155
|
+
}
|
156
|
+
|
157
|
+
private void startFusedLocation() {
|
158
|
+
|
159
|
+
Log.d("onStartFusedLocation","呼ばれた");
|
160
|
+
initLocationService();
|
161
|
+
}
|
162
|
+
|
163
|
+
private void stopFusedLocation() {
|
164
|
+
Log.d("stopFusedLocation","呼ばれた");
|
165
|
+
//firebase.auth().signOut();これでログアウトはできるが、ログアウトはしない
|
166
|
+
database.goOffline();
|
167
|
+
}
|
168
|
+
|
169
|
+
//private final LocationListener listener = new LocationListener() {
|
170
|
+
@Override
|
171
|
+
public int onStartCommand(Intent intent, int flags, int startId) {
|
172
|
+
Log.d("onStartCommand","呼ばれた");
|
173
|
+
|
174
|
+
String check =intent.getStringExtra("start/stop");
|
175
|
+
|
176
|
+
if(check.equals("start")){
|
177
|
+
startFusedLocation();
|
178
|
+
Log.d("onStartFusedLocation","呼ぶ");
|
179
|
+
}else if(check.equals("stop")){
|
180
|
+
stopFusedLocation();
|
181
|
+
Log.d("onStopFusedLocation","呼ぶ");
|
182
|
+
}
|
183
|
+
|
184
|
+
return super.onStartCommand(intent, flags, startId);
|
185
|
+
}
|
186
|
+
|
187
|
+
@Override
|
188
|
+
public void onLocationChanged (Location location){
|
189
|
+
|
190
|
+
Log.v("onLocationChanged","呼ばれた");
|
191
|
+
refreshGeoLocation(location);
|
192
|
+
|
193
|
+
|
194
|
+
}
|
195
|
+
|
196
|
+
//LocationListenerのメソッド
|
197
|
+
@Override
|
55
198
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
56
199
|
|
57
200
|
}
|
@@ -65,5 +208,49 @@
|
|
65
208
|
public void onProviderDisabled(String provider) {
|
66
209
|
|
67
210
|
}
|
211
|
+
//ここまで
|
212
|
+
|
213
|
+
|
214
|
+
@Override
|
215
|
+
public void onDestroy() {
|
216
|
+
super.onDestroy();
|
217
|
+
}
|
218
|
+
|
219
|
+
public void movieAdapter(DatabaseReference ref) {
|
220
|
+
ChildEventListener childEventListener = new ChildEventListener() {
|
221
|
+
|
222
|
+
@Override
|
223
|
+
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
//ここで、firebaseの変化を取得して、Toastを表示する
|
228
|
+
@Override
|
229
|
+
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
|
230
|
+
//```
|
231
|
+
Log.v("onChildChanged()","呼ばれた");
|
232
|
+
}
|
233
|
+
|
234
|
+
@Override
|
235
|
+
public void onChildRemoved(DataSnapshot dataSnapshot) {
|
236
|
+
Log.v("onChildRemoved()","呼ばれた");
|
237
|
+
}
|
238
|
+
|
239
|
+
@Override
|
240
|
+
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
|
241
|
+
Log.v("onChildMoved()","呼ばれた");
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
@Override
|
246
|
+
public void onCancelled(DatabaseError databaseError) {
|
247
|
+
Log.v("onCancelled()","呼ばれた");
|
248
|
+
}
|
249
|
+
};
|
250
|
+
ref.addChildEventListener(childEventListener);
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
}
|
255
|
+
|
68
|
-
```
|
256
|
+
```
|
69
|
-
gms の方のLocationを使っていたのですが、サンプルがGPSだけのLocationだったので、importを変更して、implementsを変更して、このメソッドを追加しました。
|
3
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -49,4 +49,21 @@
|
|
49
49
|
|
50
50
|
locationManager.requestLocationUpdates(bestProvider,6000,1,this);
|
51
51
|
}
|
52
|
-
```
|
52
|
+
```
|
53
|
+
```java
|
54
|
+
@Override
|
55
|
+
public void onStatusChanged(String provider, int status, Bundle extras) {
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
@Override
|
60
|
+
public void onProviderEnabled(String provider) {
|
61
|
+
|
62
|
+
}
|
63
|
+
|
64
|
+
@Override
|
65
|
+
public void onProviderDisabled(String provider) {
|
66
|
+
|
67
|
+
}
|
68
|
+
```
|
69
|
+
gms の方のLocationを使っていたのですが、サンプルがGPSだけのLocationだったので、importを変更して、implementsを変更して、このメソッドを追加しました。
|
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -36,11 +36,9 @@
|
|
36
36
|
criteria.setCostAllowed(true);
|
37
37
|
criteria.setBearingRequired(false);
|
38
38
|
|
39
|
-
|
39
|
+
|
40
40
|
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
|
41
41
|
criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
|
42
|
-
//criteria.setBearingAccuracy(Criteria.ACCURACY_HIGH);
|
43
|
-
//criteria.setSpeedAccuracy(Criteria.ACCURACY_HIGH);
|
44
42
|
|
45
43
|
Integer gpsFreqInMillis = 5000;
|
46
44
|
Integer gpsFreqInDistance = 5; // in meters
|
1
追加コード
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Serviceで、位置情報を取得したいです。
|
2
2
|
|
3
|
-
Activityでは、このようなコードで位置情報を取得できていたのですが、Serviceでは、エラーが出ます。
|
3
|
+
Activityでは、このようなコードで位置情報を取得できていたのですが、Serviceでは、エラーが出ます。エラーが出ます。アドバイスをいただけないでしょうか?
|
4
4
|
|
5
5
|
```java
|
6
6
|
bestProvider = locationManager.getBestProvider(criteria, true);
|
@@ -11,22 +11,44 @@
|
|
11
11
|
Error:(160, 24) エラー: requestLocationUpdatesに適切なメソッドが見つかりません(String,int,int,GpsService)
|
12
12
|
メソッド LocationManager.requestLocationUpdates(String,long,float,LocationListener)は使用できません
|
13
13
|
(引数の不一致: GpsServiceをLocationListenerに変換できません:)
|
14
|
-
メソッド LocationManager.requestLocationUpdates(String,long,float,PendingIntent)は使用できません
|
15
|
-
(引数の不一致: GpsServiceをPendingIntentに変換できません:)
|
16
|
-
メソッド LocationManager.requestLocationUpdates(long,float,Criteria,PendingIntent)は使用できません
|
17
|
-
|
14
|
+
メソッド
|
18
15
|
```
|
16
|
+
|
17
|
+
|
19
|
-
//
|
18
|
+
//追加コードです。
|
20
19
|
```java
|
21
|
-
|
20
|
+
|
21
|
+
protected void initLocationService(){
|
22
|
+
|
23
|
+
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
Criteria criteria = new Criteria();
|
32
|
+
criteria.setAccuracy(Criteria.ACCURACY_FINE); //setAccuracyは内部では、https://stackoverflow.com/a/17874592/1709287の用にHorizontalAccuracyの設定に変換されている。
|
33
|
+
criteria.setPowerRequirement(Criteria.POWER_HIGH);
|
34
|
+
criteria.setAltitudeRequired(false);
|
35
|
+
criteria.setSpeedRequired(true);
|
36
|
+
criteria.setCostAllowed(true);
|
37
|
+
criteria.setBearingRequired(false);
|
38
|
+
|
39
|
+
//API level 9 and up
|
40
|
+
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
|
41
|
+
criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
|
42
|
+
//criteria.setBearingAccuracy(Criteria.ACCURACY_HIGH);
|
43
|
+
//criteria.setSpeedAccuracy(Criteria.ACCURACY_HIGH);
|
44
|
+
|
45
|
+
Integer gpsFreqInMillis = 5000;
|
22
46
|
Integer gpsFreqInDistance = 5; // in meters
|
23
47
|
|
48
|
+
|
49
|
+
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
24
|
-
locationManager.
|
50
|
+
bestProvider = locationManager.getBestProvider(criteria, true)
|
51
|
+
|
25
|
-
locationManager.requestLocationUpdates(
|
52
|
+
locationManager.requestLocationUpdates(bestProvider,6000,1,this);
|
26
|
-
///このようにしても、このようなエラーが出ます。
|
27
|
-
Error:(158, 24) エラー: requestLocationUpdatesに適切なメソッドが見つかりません(Integer,Integer,Criteria,GpsService,<null>)
|
28
|
-
メソッド LocationManager.requestLocationUpdates(String,long,float,LocationListener,Looper)は使用できません
|
29
|
-
|
53
|
+
}
|
30
|
-
メソッド LocationManager.requestLocationUpdates(long,float,Criteria,LocationListener,Looper)は使用できません
|
31
|
-
(引数の不一致: GpsServiceをLocationListenerに変換できません:)
|
32
54
|
```
|