質問編集履歴

10

ログを追加しました。

2017/07/29 18:22

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -419,3 +419,17 @@
419
419
 
420
420
 
421
421
  ```
422
+
423
+ ```java
424
+
425
+ 07-30 03:21:01.964 5676-5676/com.google.android.exoplayer2.demo D/onCreate(): 呼ばれた
426
+
427
+ 07-30 03:21:01.965 5676-5676/com.google.android.exoplayer2.demo D/onStartCommand: 呼ばれた
428
+
429
+ 07-30 03:21:01.965 5676-5676/com.google.android.exoplayer2.demo D/StartLocation: 呼ばれた
430
+
431
+ 07-30 03:21:01.965 5676-5676/com.google.android.exoplayer2.demo V/initLocationService(): 呼ばれた
432
+
433
+ 07-30 03:21:01.975 5676-5676/com.google.android.exoplayer2.demo D/StartLocation: 呼ぶ
434
+
435
+ ```

9

誤字

2017/07/29 18:22

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -276,11 +276,11 @@
276
276
 
277
277
 
278
278
 
279
- private void startFusedLocation() {
279
+ private void startLocation() {
280
-
281
-
282
-
280
+
281
+
282
+
283
- Log.d("onStartLocation","呼ばれた");
283
+ Log.d("StartLocation","呼ばれた");
284
284
 
285
285
  initLocationService();
286
286
 
@@ -288,7 +288,7 @@
288
288
 
289
289
 
290
290
 
291
- private void stopFusedLocation() {
291
+ private void stopLocation() {
292
292
 
293
293
  Log.d("stopLocation","呼ばれた");
294
294
 
@@ -316,15 +316,15 @@
316
316
 
317
317
  if(check.equals("start")){
318
318
 
319
- startFusedLocation();
319
+ startLocation();
320
-
320
+
321
- Log.d("onStartLocation","呼ぶ");
321
+ Log.d("StartLocation","呼ぶ");
322
322
 
323
323
  }else if(check.equals("stop")){
324
324
 
325
- stopFusedLocation();
325
+ stopLocation();
326
-
326
+
327
- Log.d("onStopLocation","呼ぶ");
327
+ Log.d("StopLocation","呼ぶ");
328
328
 
329
329
  }
330
330
 
@@ -406,7 +406,7 @@
406
406
 
407
407
  }
408
408
 
409
- };
409
+ };
410
410
 
411
411
  ref.addChildEventListener(childEventListener);
412
412
 
@@ -416,4 +416,6 @@
416
416
 
417
417
 
418
418
 
419
+
420
+
419
421
  ```

8

誤字

2017/07/29 18:18

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -92,7 +92,7 @@
92
92
 
93
93
 
94
94
 
95
-
95
+
96
96
 
97
97
 
98
98
 
@@ -280,7 +280,7 @@
280
280
 
281
281
 
282
282
 
283
- Log.d("onStartFusedLocation","呼ばれた");
283
+ Log.d("onStartLocation","呼ばれた");
284
284
 
285
285
  initLocationService();
286
286
 
@@ -290,7 +290,7 @@
290
290
 
291
291
  private void stopFusedLocation() {
292
292
 
293
- Log.d("stopFusedLocation","呼ばれた");
293
+ Log.d("stopLocation","呼ばれた");
294
294
 
295
295
  //firebase.auth().signOut();これでログアウトはできるが、ログアウトはしない
296
296
 
@@ -318,13 +318,13 @@
318
318
 
319
319
  startFusedLocation();
320
320
 
321
- Log.d("onStartFusedLocation","呼ぶ");
321
+ Log.d("onStartLocation","呼ぶ");
322
322
 
323
323
  }else if(check.equals("stop")){
324
324
 
325
325
  stopFusedLocation();
326
326
 
327
- Log.d("onStopFusedLocation","呼ぶ");
327
+ Log.d("onStopLocation","呼ぶ");
328
328
 
329
329
  }
330
330
 
@@ -406,7 +406,7 @@
406
406
 
407
407
  }
408
408
 
409
- };
409
+ };
410
410
 
411
411
  ref.addChildEventListener(childEventListener);
412
412
 
@@ -416,6 +416,4 @@
416
416
 
417
417
 
418
418
 
419
-
420
-
421
419
  ```

7

コードの変更

2017/07/29 17:07

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -26,12 +26,8 @@
26
26
 
27
27
  import android.os.IBinder;
28
28
 
29
- //import com.google.android.gms.location.LocationListener;
30
-
31
29
  import android.location.LocationListener;
32
30
 
33
- import com.google.android.gms.common.api.GoogleApiClient;
34
-
35
31
  import android.content.pm.PackageManager;
36
32
 
37
33
  import android.location.Location;
@@ -42,12 +38,6 @@
42
38
 
43
39
  import android.util.Log;
44
40
 
45
- import android.widget.TextView;
46
-
47
- import com.google.android.gms.location.FusedLocationProviderApi;
48
-
49
- import com.google.android.gms.location.LocationRequest;
50
-
51
41
  import com.google.android.gms.common.ConnectionResult;
52
42
 
53
43
  import com.google.firebase.database.ChildEventListener;
@@ -64,11 +54,7 @@
64
54
 
65
55
 
66
56
 
67
- public class GpsService extends Service implements
57
+ public class GpsService extends Service implements LocationListener{
68
-
69
- GoogleApiClient.ConnectionCallbacks,
70
-
71
- GoogleApiClient.OnConnectionFailedListener,LocationListener{
72
58
 
73
59
 
74
60
 
@@ -106,25 +92,245 @@
106
92
 
107
93
 
108
94
 
95
+
96
+
97
+
98
+
99
+ public GpsService() {
100
+
101
+ }
102
+
103
+
104
+
105
+ //serviceだからいらないかも removeupdatesは必要
106
+
107
+ // @Override
108
+
109
+ // protected void onPause(){
110
+
111
+ // super.onPause();
112
+
113
+ // locationManager.removeUpdates(this);
114
+
115
+ // mLocationManager.removeUpdates(listener);
116
+
117
+ // }
118
+
119
+
120
+
121
+ protected void initLocationService() {
122
+
123
+ Log.v("initLocationService()", "呼ばれた");
124
+
125
+
126
+
127
+ 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) {
128
+
129
+ return;
130
+
131
+ }
132
+
133
+ 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) {
134
+
135
+ return;
136
+
137
+ }
138
+
139
+
140
+
141
+ Criteria criteria = new Criteria();
142
+
143
+ criteria.setAccuracy(Criteria.ACCURACY_FINE); //setAccuracyは内部では、https://stackoverflow.com/a/17874592/1709287の用にHorizontalAccuracyの設定に変換されている。
144
+
145
+ criteria.setPowerRequirement(Criteria.POWER_HIGH);
146
+
147
+ criteria.setAltitudeRequired(false);
148
+
149
+ criteria.setSpeedRequired(true);
150
+
151
+ criteria.setCostAllowed(true);
152
+
153
+ criteria.setBearingRequired(false);
154
+
155
+ criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
156
+
157
+ criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
158
+
159
+
160
+
161
+ // locationManager.registerGnssStatusCallback()
162
+
163
+ // locationManager.requestLocationUpdates(gpsFreqInMillis, gpsFreqInDistance, criteria, this, null);
164
+
165
+
166
+
167
+ LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
168
+
169
+ String bestProvider = locationManager.getBestProvider(criteria, true);
170
+
171
+ locationManager.requestLocationUpdates(bestProvider, 6000, 1, this);
172
+
173
+ }
174
+
175
+
176
+
177
+ @Override
178
+
179
+ public void onLocationChanged(Location location) {
180
+
181
+
182
+
183
+ Log.v("onLocationChanged", "呼ばれた");
184
+
185
+ refreshGeoLocation(location);
186
+
187
+ }
188
+
189
+
190
+
191
+ //LocationListenerのメソッド
192
+
193
+ @Override
194
+
195
+ public void onStatusChanged(String provider, int status, Bundle extras) {
196
+
197
+
198
+
199
+ }
200
+
201
+
202
+
203
+ @Override
204
+
205
+ public void onProviderEnabled(String provider) {
206
+
207
+
208
+
209
+ }
210
+
211
+
212
+
213
+ @Override
214
+
215
+ public void onProviderDisabled(String provider) {
216
+
217
+
218
+
219
+ }
220
+
221
+
222
+
223
+
224
+
225
+ //ここまで
226
+
227
+
228
+
229
+ // 位置情報のリスナーを取得して登録する
230
+
231
+ //sensorEventListener = new GpsLocationListener(sensorValueTextView);
232
+
233
+
234
+
235
+
236
+
237
+ // public class LocationServiceBinder extends Binder {
238
+
239
+ // public com.google.android.exoplayer2.demo.GpsService getService() {
240
+
241
+ // return com.google.android.exoplayer2.demo.GpsService.this;
242
+
243
+ // }
244
+
245
+ // }
246
+
247
+ protected void refreshGeoLocation(Location location){
248
+
249
+ Log.v("refreshGeoLocation","呼ばれた");
250
+
251
+ String user = FirebaseAuth.getInstance().getCurrentUser().getUid();
252
+
253
+ DatabaseReference ref = database.getReference().child("users").child(user);
254
+
255
+ DatabaseReference latitudeRef = ref.child("latitude");
256
+
257
+ DatabaseReference longitudeRef = ref.child("longitude");
258
+
259
+ latitudeRef.setValue(location.getLatitude());
260
+
261
+ longitudeRef.setValue(location.getLongitude());
262
+
263
+ }
264
+
109
265
 
110
266
 
111
267
  @Override
112
268
 
113
- public void onConnected(Bundle bundle) {
269
+ public IBinder onBind(Intent intent) {
114
-
270
+
115
- Log.d("onConnected()","呼ばれた");
271
+ Log.v("onBind","呼ばれた");
272
+
116
-
273
+ throw new UnsupportedOperationException("Not yet implemented");
274
+
117
- }
275
+ }
276
+
277
+
278
+
118
-
279
+ private void startFusedLocation() {
280
+
281
+
282
+
119
-
283
+ Log.d("onStartFusedLocation","呼ばれた");
284
+
285
+ initLocationService();
286
+
287
+ }
288
+
289
+
290
+
291
+ private void stopFusedLocation() {
292
+
293
+ Log.d("stopFusedLocation","呼ばれた");
294
+
295
+ //firebase.auth().signOut();これでログアウトはできるが、ログアウトはしない
296
+
297
+ database.goOffline();
298
+
299
+ }
300
+
301
+
302
+
303
+ //private final LocationListener listener = new LocationListener() {
120
304
 
121
305
  @Override
122
306
 
123
- public void onConnectionSuspended(int i) {
307
+ public int onStartCommand(Intent intent, int flags, int startId) {
308
+
124
-
309
+ Log.d("onStartCommand","呼ばれた");
310
+
311
+
312
+
313
+ String check =intent.getStringExtra("start/stop");
314
+
315
+
316
+
317
+ if(check.equals("start")){
318
+
319
+ startFusedLocation();
320
+
321
+ Log.d("onStartFusedLocation","呼ぶ");
322
+
323
+ }else if(check.equals("stop")){
324
+
325
+ stopFusedLocation();
326
+
125
- Log.d("onConnectionSuspended()","");
327
+ Log.d("onStopFusedLocation","呼ぶ");
328
+
126
-
329
+ }
330
+
331
+
332
+
127
-
333
+ return super.onStartCommand(intent, flags, startId);
128
334
 
129
335
  }
130
336
 
@@ -132,278 +338,6 @@
132
338
 
133
339
  @Override
134
340
 
135
- public void onConnectionFailed(ConnectionResult connectionResult) {
136
-
137
- Log.v("onConnectionFailed()","呼ばれた");
138
-
139
-
140
-
141
- if (mResolvingError) {
142
-
143
- // Already attempting to resolve an error.
144
-
145
- Log.d("", "Already attempting to resolve an error");
146
-
147
-
148
-
149
- return;
150
-
151
- } else if (connectionResult.hasResolution()) {
152
-
153
-
154
-
155
- } else {
156
-
157
- mResolvingError = true;
158
-
159
- }
160
-
161
- }
162
-
163
-
164
-
165
- public GpsService() {
166
-
167
- }
168
-
169
-
170
-
171
- //serviceだからいらないかも removeupdatesは必要
172
-
173
- // @Override
174
-
175
- // protected void onPause(){
176
-
177
- // super.onPause();
178
-
179
- // locationManager.removeUpdates(this);
180
-
181
- // mLocationManager.removeUpdates(listener);
182
-
183
- // }
184
-
185
-
186
-
187
- protected void initLocationService() {
188
-
189
- Log.v("initLocationService()", "呼ばれた");
190
-
191
-
192
-
193
- 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) {
194
-
195
- return;
196
-
197
- }
198
-
199
- 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) {
200
-
201
- return;
202
-
203
- }
204
-
205
-
206
-
207
- Criteria criteria = new Criteria();
208
-
209
- criteria.setAccuracy(Criteria.ACCURACY_FINE); //setAccuracyは内部では、https://stackoverflow.com/a/17874592/1709287の用にHorizontalAccuracyの設定に変換されている。
210
-
211
- criteria.setPowerRequirement(Criteria.POWER_HIGH);
212
-
213
- criteria.setAltitudeRequired(false);
214
-
215
- criteria.setSpeedRequired(true);
216
-
217
- criteria.setCostAllowed(true);
218
-
219
- criteria.setBearingRequired(false);
220
-
221
- criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
222
-
223
- criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
224
-
225
-
226
-
227
- // locationManager.registerGnssStatusCallback()
228
-
229
- // locationManager.requestLocationUpdates(gpsFreqInMillis, gpsFreqInDistance, criteria, this, null);
230
-
231
-
232
-
233
- LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
234
-
235
- String bestProvider = locationManager.getBestProvider(criteria, true);
236
-
237
- locationManager.requestLocationUpdates(bestProvider, 6000, 1, this);
238
-
239
- }
240
-
241
-
242
-
243
- @Override
244
-
245
- public void onLocationChanged(Location location) {
246
-
247
-
248
-
249
- Log.v("onLocationChanged", "呼ばれた");
250
-
251
- refreshGeoLocation(location);
252
-
253
- }
254
-
255
-
256
-
257
- //LocationListenerのメソッド
258
-
259
- @Override
260
-
261
- public void onStatusChanged(String provider, int status, Bundle extras) {
262
-
263
-
264
-
265
- }
266
-
267
-
268
-
269
- @Override
270
-
271
- public void onProviderEnabled(String provider) {
272
-
273
-
274
-
275
- }
276
-
277
-
278
-
279
- @Override
280
-
281
- public void onProviderDisabled(String provider) {
282
-
283
-
284
-
285
- }
286
-
287
-
288
-
289
-
290
-
291
- //ここまで
292
-
293
-
294
-
295
- // 位置情報のリスナーを取得して登録する
296
-
297
- //sensorEventListener = new GpsLocationListener(sensorValueTextView);
298
-
299
-
300
-
301
-
302
-
303
- public class LocationServiceBinder extends Binder {
304
-
305
- public com.google.android.exoplayer2.demo.GpsService getService() {
306
-
307
- return com.google.android.exoplayer2.demo.GpsService.this;
308
-
309
- }
310
-
311
- }
312
-
313
- protected void refreshGeoLocation(Location location){
314
-
315
- Log.v("refreshGeoLocation","呼ばれた");
316
-
317
- String user = FirebaseAuth.getInstance().getCurrentUser().getUid();
318
-
319
- DatabaseReference ref = database.getReference().child("users").child(user);
320
-
321
- DatabaseReference latitudeRef = ref.child("latitude");
322
-
323
- DatabaseReference longitudeRef = ref.child("longitude");
324
-
325
- latitudeRef.setValue(location.getLatitude());
326
-
327
- longitudeRef.setValue(location.getLongitude());
328
-
329
- }
330
-
331
-
332
-
333
- @Override
334
-
335
- public IBinder onBind(Intent intent) {
336
-
337
- Log.v("onBind","呼ばれた");
338
-
339
- throw new UnsupportedOperationException("Not yet implemented");
340
-
341
- }
342
-
343
-
344
-
345
- private void startFusedLocation() {
346
-
347
-
348
-
349
- Log.d("onStartFusedLocation","呼ばれた");
350
-
351
- initLocationService();
352
-
353
- }
354
-
355
-
356
-
357
- private void stopFusedLocation() {
358
-
359
- Log.d("stopFusedLocation","呼ばれた");
360
-
361
- //firebase.auth().signOut();これでログアウトはできるが、ログアウトはしない
362
-
363
- database.goOffline();
364
-
365
- }
366
-
367
-
368
-
369
- //private final LocationListener listener = new LocationListener() {
370
-
371
- @Override
372
-
373
- public int onStartCommand(Intent intent, int flags, int startId) {
374
-
375
- Log.d("onStartCommand","呼ばれた");
376
-
377
-
378
-
379
- String check =intent.getStringExtra("start/stop");
380
-
381
-
382
-
383
- if(check.equals("start")){
384
-
385
- startFusedLocation();
386
-
387
- Log.d("onStartFusedLocation","呼ぶ");
388
-
389
- }else if(check.equals("stop")){
390
-
391
- stopFusedLocation();
392
-
393
- Log.d("onStopFusedLocation","呼ぶ");
394
-
395
- }
396
-
397
-
398
-
399
- return super.onStartCommand(intent, flags, startId);
400
-
401
- }
402
-
403
-
404
-
405
- @Override
406
-
407
341
  public void onDestroy() {
408
342
 
409
343
  super.onDestroy();

6

誤字

2017/07/29 16:08

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
 
8
8
 
9
+
10
+
9
11
  ```java
10
12
 
11
13
  package com.google.android.exoplayer2.demo;
@@ -74,6 +76,8 @@
74
76
 
75
77
  final FirebaseDatabase database = FirebaseDatabase.getInstance();
76
78
 
79
+ private LocationListener sensorEventListener; // onPause()
80
+
77
81
 
78
82
 
79
83
  public class GpsServiceBinder extends Binder {
@@ -102,7 +106,7 @@
102
106
 
103
107
 
104
108
 
105
-
109
+
106
110
 
107
111
  @Override
108
112
 
@@ -156,7 +160,7 @@
156
160
 
157
161
  }
158
162
 
159
-
163
+
160
164
 
161
165
  public GpsService() {
162
166
 
@@ -174,13 +178,15 @@
174
178
 
175
179
  // locationManager.removeUpdates(this);
176
180
 
181
+ // mLocationManager.removeUpdates(listener);
182
+
177
183
  // }
178
184
 
179
-
180
-
185
+
186
+
181
- protected void initLocationService(){
187
+ protected void initLocationService() {
182
-
188
+
183
- Log.v("initLocationService()","呼ばれた");
189
+ Log.v("initLocationService()", "呼ばれた");
184
190
 
185
191
 
186
192
 
@@ -196,7 +202,7 @@
196
202
 
197
203
  }
198
204
 
199
-
205
+
200
206
 
201
207
  Criteria criteria = new Criteria();
202
208
 
@@ -228,9 +234,69 @@
228
234
 
229
235
  String bestProvider = locationManager.getBestProvider(criteria, true);
230
236
 
231
- locationManager.requestLocationUpdates(bestProvider,6000,1,this);
237
+ locationManager.requestLocationUpdates(bestProvider, 6000, 1, this);
232
-
238
+
233
- }
239
+ }
240
+
241
+
242
+
243
+ @Override
244
+
245
+ public void onLocationChanged(Location location) {
246
+
247
+
248
+
249
+ Log.v("onLocationChanged", "呼ばれた");
250
+
251
+ refreshGeoLocation(location);
252
+
253
+ }
254
+
255
+
256
+
257
+ //LocationListenerのメソッド
258
+
259
+ @Override
260
+
261
+ public void onStatusChanged(String provider, int status, Bundle extras) {
262
+
263
+
264
+
265
+ }
266
+
267
+
268
+
269
+ @Override
270
+
271
+ public void onProviderEnabled(String provider) {
272
+
273
+
274
+
275
+ }
276
+
277
+
278
+
279
+ @Override
280
+
281
+ public void onProviderDisabled(String provider) {
282
+
283
+
284
+
285
+ }
286
+
287
+
288
+
289
+
290
+
291
+ //ここまで
292
+
293
+
294
+
295
+ // 位置情報のリスナーを取得して登録する
296
+
297
+ //sensorEventListener = new GpsLocationListener(sensorValueTextView);
298
+
299
+
234
300
 
235
301
 
236
302
 
@@ -262,7 +328,7 @@
262
328
 
263
329
  }
264
330
 
265
-
331
+
266
332
 
267
333
  @Override
268
334
 
@@ -338,54 +404,6 @@
338
404
 
339
405
  @Override
340
406
 
341
- public void onLocationChanged (Location location){
342
-
343
-
344
-
345
- Log.v("onLocationChanged","呼ばれた");
346
-
347
- refreshGeoLocation(location);
348
-
349
- }
350
-
351
-
352
-
353
- //LocationListenerのメソッド
354
-
355
- @Override
356
-
357
- public void onStatusChanged(String provider, int status, Bundle extras) {
358
-
359
-
360
-
361
- }
362
-
363
-
364
-
365
- @Override
366
-
367
- public void onProviderEnabled(String provider) {
368
-
369
-
370
-
371
- }
372
-
373
-
374
-
375
- @Override
376
-
377
- public void onProviderDisabled(String provider) {
378
-
379
-
380
-
381
- }
382
-
383
- //ここまで
384
-
385
-
386
-
387
- @Override
388
-
389
407
  public void onDestroy() {
390
408
 
391
409
  super.onDestroy();
@@ -464,4 +482,6 @@
464
482
 
465
483
 
466
484
 
485
+
486
+
467
487
  ```

5

誤字

2017/07/29 14:04

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -102,9 +102,7 @@
102
102
 
103
103
 
104
104
 
105
-
106
-
107
-
105
+
108
106
 
109
107
  @Override
110
108
 
@@ -158,9 +156,7 @@
158
156
 
159
157
  }
160
158
 
161
-
162
-
163
-
159
+
164
160
 
165
161
  public GpsService() {
166
162
 
@@ -180,9 +176,7 @@
180
176
 
181
177
  // }
182
178
 
183
-
184
-
185
-
179
+
186
180
 
187
181
  protected void initLocationService(){
188
182
 
@@ -202,9 +196,7 @@
202
196
 
203
197
  }
204
198
 
205
-
206
-
207
-
199
+
208
200
 
209
201
  Criteria criteria = new Criteria();
210
202
 
@@ -236,23 +228,9 @@
236
228
 
237
229
  String bestProvider = locationManager.getBestProvider(criteria, true);
238
230
 
239
-
240
-
241
-
242
-
243
231
  locationManager.requestLocationUpdates(bestProvider,6000,1,this);
244
232
 
245
-
246
-
247
-
248
-
249
- }
233
+ }
250
-
251
- /////////////////////////////////////////////////多分いらないやつ
252
-
253
-
254
-
255
-
256
234
 
257
235
 
258
236
 
@@ -266,20 +244,10 @@
266
244
 
267
245
  }
268
246
 
269
-
270
-
271
-
272
-
273
247
  protected void refreshGeoLocation(Location location){
274
248
 
275
-
276
-
277
249
  Log.v("refreshGeoLocation","呼ばれた");
278
250
 
279
-
280
-
281
-
282
-
283
251
  String user = FirebaseAuth.getInstance().getCurrentUser().getUid();
284
252
 
285
253
  DatabaseReference ref = database.getReference().child("users").child(user);
@@ -294,9 +262,7 @@
294
262
 
295
263
  }
296
264
 
297
-
298
-
299
-
265
+
300
266
 
301
267
  @Override
302
268
 
@@ -380,10 +346,6 @@
380
346
 
381
347
  refreshGeoLocation(location);
382
348
 
383
-
384
-
385
-
386
-
387
349
  }
388
350
 
389
351
 
@@ -420,9 +382,7 @@
420
382
 
421
383
  //ここまで
422
384
 
423
-
424
-
425
-
385
+
426
386
 
427
387
  @Override
428
388
 
@@ -500,10 +460,6 @@
500
460
 
501
461
  }
502
462
 
503
-
504
-
505
-
506
-
507
463
  }
508
464
 
509
465
 

4

コードの変更

2017/07/29 13:20

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -8,130 +8,504 @@
8
8
 
9
9
  ```java
10
10
 
11
- bestProvider = locationManager.getBestProvider(criteria, true);
12
-
13
-
14
-
15
- locationManager.requestLocationUpdates(bestProvider, 6000, 1, GpsService.this);
16
-
17
-
18
-
19
- //このようなエラーが出ます。
20
-
21
- Error:(160, 24) エラー: requestLocationUpdatesに適切なメソッドが見つかりません(String,int,int,GpsService)
22
-
23
- メソッド LocationManager.requestLocationUpdates(String,long,float,LocationListener)は使用できません
24
-
25
- (引数の不一致: GpsServiceをLocationListenerに変換できません:)
26
-
27
- メソッド
11
+ package com.google.android.exoplayer2.demo;
12
+
13
+
14
+
15
+ import android.app.Service;
16
+
17
+ import android.content.Intent;
18
+
19
+ import android.location.Criteria;
20
+
21
+ import android.location.LocationManager;
22
+
23
+ import android.os.Binder;
24
+
25
+ import android.os.IBinder;
26
+
27
+ //import com.google.android.gms.location.LocationListener;
28
+
29
+ import android.location.LocationListener;
30
+
31
+ import com.google.android.gms.common.api.GoogleApiClient;
32
+
33
+ import android.content.pm.PackageManager;
34
+
35
+ import android.location.Location;
36
+
37
+ import android.support.v4.app.ActivityCompat;
38
+
39
+ import android.os.Bundle;
40
+
41
+ import android.util.Log;
42
+
43
+ import android.widget.TextView;
44
+
45
+ import com.google.android.gms.location.FusedLocationProviderApi;
46
+
47
+ import com.google.android.gms.location.LocationRequest;
48
+
49
+ import com.google.android.gms.common.ConnectionResult;
50
+
51
+ import com.google.firebase.database.ChildEventListener;
52
+
53
+ import com.google.firebase.database.DataSnapshot;
54
+
55
+ import com.google.firebase.database.DatabaseError;
56
+
57
+ import com.google.firebase.database.DatabaseReference;
58
+
59
+ import com.google.firebase.database.FirebaseDatabase;
60
+
61
+ import com.google.firebase.auth.FirebaseAuth;
62
+
63
+
64
+
65
+ public class GpsService extends Service implements
66
+
67
+ GoogleApiClient.ConnectionCallbacks,
68
+
69
+ GoogleApiClient.OnConnectionFailedListener,LocationListener{
70
+
71
+
72
+
73
+ private boolean mResolvingError = false;
74
+
75
+ final FirebaseDatabase database = FirebaseDatabase.getInstance();
76
+
77
+
78
+
79
+ public class GpsServiceBinder extends Binder {
80
+
81
+ public GpsService getService() {
82
+
83
+ return GpsService.this;
84
+
85
+ }
86
+
87
+ }
88
+
89
+
90
+
91
+ @Override
92
+
93
+ public void onCreate() {
94
+
95
+ super.onCreate();
96
+
97
+
98
+
99
+ Log.d("onCreate()","呼ばれた");
100
+
101
+ }
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+ @Override
110
+
111
+ public void onConnected(Bundle bundle) {
112
+
113
+ Log.d("onConnected()","呼ばれた");
114
+
115
+ }
116
+
117
+
118
+
119
+ @Override
120
+
121
+ public void onConnectionSuspended(int i) {
122
+
123
+ Log.d("onConnectionSuspended()","");
124
+
125
+
126
+
127
+ }
128
+
129
+
130
+
131
+ @Override
132
+
133
+ public void onConnectionFailed(ConnectionResult connectionResult) {
134
+
135
+ Log.v("onConnectionFailed()","呼ばれた");
136
+
137
+
138
+
139
+ if (mResolvingError) {
140
+
141
+ // Already attempting to resolve an error.
142
+
143
+ Log.d("", "Already attempting to resolve an error");
144
+
145
+
146
+
147
+ return;
148
+
149
+ } else if (connectionResult.hasResolution()) {
150
+
151
+
152
+
153
+ } else {
154
+
155
+ mResolvingError = true;
156
+
157
+ }
158
+
159
+ }
160
+
161
+
162
+
163
+
164
+
165
+ public GpsService() {
166
+
167
+ }
168
+
169
+
170
+
171
+ //serviceだからいらないかも removeupdatesは必要
172
+
173
+ // @Override
174
+
175
+ // protected void onPause(){
176
+
177
+ // super.onPause();
178
+
179
+ // locationManager.removeUpdates(this);
180
+
181
+ // }
182
+
183
+
184
+
185
+
186
+
187
+ protected void initLocationService(){
188
+
189
+ Log.v("initLocationService()","呼ばれた");
190
+
191
+
192
+
193
+ 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) {
194
+
195
+ return;
196
+
197
+ }
198
+
199
+ 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) {
200
+
201
+ return;
202
+
203
+ }
204
+
205
+
206
+
207
+
208
+
209
+ Criteria criteria = new Criteria();
210
+
211
+ criteria.setAccuracy(Criteria.ACCURACY_FINE); //setAccuracyは内部では、https://stackoverflow.com/a/17874592/1709287の用にHorizontalAccuracyの設定に変換されている。
212
+
213
+ criteria.setPowerRequirement(Criteria.POWER_HIGH);
214
+
215
+ criteria.setAltitudeRequired(false);
216
+
217
+ criteria.setSpeedRequired(true);
218
+
219
+ criteria.setCostAllowed(true);
220
+
221
+ criteria.setBearingRequired(false);
222
+
223
+ criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
224
+
225
+ criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
226
+
227
+
228
+
229
+ // locationManager.registerGnssStatusCallback()
230
+
231
+ // locationManager.requestLocationUpdates(gpsFreqInMillis, gpsFreqInDistance, criteria, this, null);
232
+
233
+
234
+
235
+ LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
236
+
237
+ String bestProvider = locationManager.getBestProvider(criteria, true);
238
+
239
+
240
+
241
+
242
+
243
+ locationManager.requestLocationUpdates(bestProvider,6000,1,this);
244
+
245
+
246
+
247
+
248
+
249
+ }
250
+
251
+ /////////////////////////////////////////////////多分いらないやつ
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+ public class LocationServiceBinder extends Binder {
260
+
261
+ public com.google.android.exoplayer2.demo.GpsService getService() {
262
+
263
+ return com.google.android.exoplayer2.demo.GpsService.this;
264
+
265
+ }
266
+
267
+ }
268
+
269
+
270
+
271
+
272
+
273
+ protected void refreshGeoLocation(Location location){
274
+
275
+
276
+
277
+ Log.v("refreshGeoLocation","呼ばれた");
278
+
279
+
280
+
281
+
282
+
283
+ String user = FirebaseAuth.getInstance().getCurrentUser().getUid();
284
+
285
+ DatabaseReference ref = database.getReference().child("users").child(user);
286
+
287
+ DatabaseReference latitudeRef = ref.child("latitude");
288
+
289
+ DatabaseReference longitudeRef = ref.child("longitude");
290
+
291
+ latitudeRef.setValue(location.getLatitude());
292
+
293
+ longitudeRef.setValue(location.getLongitude());
294
+
295
+ }
296
+
297
+
298
+
299
+
300
+
301
+ @Override
302
+
303
+ public IBinder onBind(Intent intent) {
304
+
305
+ Log.v("onBind","呼ばれた");
306
+
307
+ throw new UnsupportedOperationException("Not yet implemented");
308
+
309
+ }
310
+
311
+
312
+
313
+ private void startFusedLocation() {
314
+
315
+
316
+
317
+ Log.d("onStartFusedLocation","呼ばれた");
318
+
319
+ initLocationService();
320
+
321
+ }
322
+
323
+
324
+
325
+ private void stopFusedLocation() {
326
+
327
+ Log.d("stopFusedLocation","呼ばれた");
328
+
329
+ //firebase.auth().signOut();これでログアウトはできるが、ログアウトはしない
330
+
331
+ database.goOffline();
332
+
333
+ }
334
+
335
+
336
+
337
+ //private final LocationListener listener = new LocationListener() {
338
+
339
+ @Override
340
+
341
+ public int onStartCommand(Intent intent, int flags, int startId) {
342
+
343
+ Log.d("onStartCommand","呼ばれた");
344
+
345
+
346
+
347
+ String check =intent.getStringExtra("start/stop");
348
+
349
+
350
+
351
+ if(check.equals("start")){
352
+
353
+ startFusedLocation();
354
+
355
+ Log.d("onStartFusedLocation","呼ぶ");
356
+
357
+ }else if(check.equals("stop")){
358
+
359
+ stopFusedLocation();
360
+
361
+ Log.d("onStopFusedLocation","呼ぶ");
362
+
363
+ }
364
+
365
+
366
+
367
+ return super.onStartCommand(intent, flags, startId);
368
+
369
+ }
370
+
371
+
372
+
373
+ @Override
374
+
375
+ public void onLocationChanged (Location location){
376
+
377
+
378
+
379
+ Log.v("onLocationChanged","呼ばれた");
380
+
381
+ refreshGeoLocation(location);
382
+
383
+
384
+
385
+
386
+
387
+ }
388
+
389
+
390
+
391
+ //LocationListenerのメソッド
392
+
393
+ @Override
394
+
395
+ public void onStatusChanged(String provider, int status, Bundle extras) {
396
+
397
+
398
+
399
+ }
400
+
401
+
402
+
403
+ @Override
404
+
405
+ public void onProviderEnabled(String provider) {
406
+
407
+
408
+
409
+ }
410
+
411
+
412
+
413
+ @Override
414
+
415
+ public void onProviderDisabled(String provider) {
416
+
417
+
418
+
419
+ }
420
+
421
+ //ここまで
422
+
423
+
424
+
425
+
426
+
427
+ @Override
428
+
429
+ public void onDestroy() {
430
+
431
+ super.onDestroy();
432
+
433
+ }
434
+
435
+
436
+
437
+ public void movieAdapter(DatabaseReference ref) {
438
+
439
+ ChildEventListener childEventListener = new ChildEventListener() {
440
+
441
+
442
+
443
+ @Override
444
+
445
+ public void onChildAdded(DataSnapshot dataSnapshot, String s) {
446
+
447
+
448
+
449
+ }
450
+
451
+
452
+
453
+ //ここで、firebaseの変化を取得して、Toastを表示する
454
+
455
+ @Override
456
+
457
+ public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
458
+
459
+ //```
460
+
461
+ Log.v("onChildChanged()","呼ばれた");
462
+
463
+ }
464
+
465
+
466
+
467
+ @Override
468
+
469
+ public void onChildRemoved(DataSnapshot dataSnapshot) {
470
+
471
+ Log.v("onChildRemoved()","呼ばれた");
472
+
473
+ }
474
+
475
+
476
+
477
+ @Override
478
+
479
+ public void onChildMoved(DataSnapshot dataSnapshot, String s) {
480
+
481
+ Log.v("onChildMoved()","呼ばれた");
482
+
483
+
484
+
485
+ }
486
+
487
+
488
+
489
+ @Override
490
+
491
+ public void onCancelled(DatabaseError databaseError) {
492
+
493
+ Log.v("onCancelled()","呼ばれた");
494
+
495
+ }
496
+
497
+ };
498
+
499
+ ref.addChildEventListener(childEventListener);
500
+
501
+ }
502
+
503
+
504
+
505
+
506
+
507
+ }
508
+
509
+
28
510
 
29
511
  ```
30
-
31
-
32
-
33
-
34
-
35
- //追加コードです。
36
-
37
- ```java
38
-
39
-
40
-
41
- protected void initLocationService(){
42
-
43
-
44
-
45
- 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) {
46
-
47
- return;
48
-
49
- }
50
-
51
- 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) {
52
-
53
- return;
54
-
55
- }
56
-
57
-
58
-
59
-
60
-
61
- Criteria criteria = new Criteria();
62
-
63
- criteria.setAccuracy(Criteria.ACCURACY_FINE); //setAccuracyは内部では、https://stackoverflow.com/a/17874592/1709287の用にHorizontalAccuracyの設定に変換されている。
64
-
65
- criteria.setPowerRequirement(Criteria.POWER_HIGH);
66
-
67
- criteria.setAltitudeRequired(false);
68
-
69
- criteria.setSpeedRequired(true);
70
-
71
- criteria.setCostAllowed(true);
72
-
73
- criteria.setBearingRequired(false);
74
-
75
-
76
-
77
-
78
-
79
- criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
80
-
81
- criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
82
-
83
-
84
-
85
- Integer gpsFreqInMillis = 5000;
86
-
87
- Integer gpsFreqInDistance = 5; // in meters
88
-
89
-
90
-
91
-
92
-
93
- LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
94
-
95
- bestProvider = locationManager.getBestProvider(criteria, true)
96
-
97
-
98
-
99
- locationManager.requestLocationUpdates(bestProvider,6000,1,this);
100
-
101
- }
102
-
103
- ```
104
-
105
- ```java
106
-
107
- @Override
108
-
109
- public void onStatusChanged(String provider, int status, Bundle extras) {
110
-
111
-
112
-
113
- }
114
-
115
-
116
-
117
- @Override
118
-
119
- public void onProviderEnabled(String provider) {
120
-
121
-
122
-
123
- }
124
-
125
-
126
-
127
- @Override
128
-
129
- public void onProviderDisabled(String provider) {
130
-
131
-
132
-
133
- }
134
-
135
- ```
136
-
137
- gms の方のLocationを使っていたのですが、サンプルがGPSだけのLocationだったので、importを変更して、implementsを変更して、このメソッドを追加しました。

3

追加

2017/07/29 13:16

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -101,3 +101,37 @@
101
101
  }
102
102
 
103
103
  ```
104
+
105
+ ```java
106
+
107
+ @Override
108
+
109
+ public void onStatusChanged(String provider, int status, Bundle extras) {
110
+
111
+
112
+
113
+ }
114
+
115
+
116
+
117
+ @Override
118
+
119
+ public void onProviderEnabled(String provider) {
120
+
121
+
122
+
123
+ }
124
+
125
+
126
+
127
+ @Override
128
+
129
+ public void onProviderDisabled(String provider) {
130
+
131
+
132
+
133
+ }
134
+
135
+ ```
136
+
137
+ gms の方のLocationを使っていたのですが、サンプルがGPSだけのLocationだったので、importを変更して、implementsを変更して、このメソッドを追加しました。

2

誤字

2017/07/29 12:33

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -74,15 +74,11 @@
74
74
 
75
75
 
76
76
 
77
- //API level 9 and up
77
+
78
78
 
79
79
  criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
80
80
 
81
81
  criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
82
-
83
- //criteria.setBearingAccuracy(Criteria.ACCURACY_HIGH);
84
-
85
- //criteria.setSpeedAccuracy(Criteria.ACCURACY_HIGH);
86
82
 
87
83
 
88
84
 

1

追加コード

2017/07/29 12:31

投稿

atatatatata
atatatatata

スコア77

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- Activityでは、このようなコードで位置情報を取得できていたのですが、Serviceでは、エラーが出ます。2通りを試したのですが、同じエラーが出ます。アドバイスをいただけないでしょうか?
5
+ Activityでは、このようなコードで位置情報を取得できていたのですが、Serviceでは、エラーが出ます。エラーが出ます。アドバイスをいただけないでしょうか?
6
6
 
7
7
 
8
8
 
@@ -24,40 +24,84 @@
24
24
 
25
25
  (引数の不一致: GpsServiceをLocationListenerに変換できません:)
26
26
 
27
- メソッド LocationManager.requestLocationUpdates(String,long,float,PendingIntent)は使用できません
28
-
29
- (引数の不一致: GpsServiceをPendingIntentに変換できません:)
30
-
31
- メソッド LocationManager.requestLocationUpdates(long,float,Criteria,PendingIntent)は使用できません
32
-
33
- (引数の不一致: Stringをlongに変換できません:)
27
+ メソッド
34
28
 
35
29
  ```
36
30
 
31
+
32
+
33
+
34
+
37
- //そここのように書き換えたのでが、同じエラーが出ました
35
+ //追加コードです。
38
36
 
39
37
  ```java
40
38
 
41
- Integer gpsFreqInMillis = 5000;
39
+
40
+
41
+ protected void initLocationService(){
42
+
43
+
44
+
45
+ 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) {
46
+
47
+ return;
48
+
49
+ }
50
+
51
+ 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) {
52
+
53
+ return;
54
+
55
+ }
56
+
57
+
58
+
59
+
60
+
61
+ Criteria criteria = new Criteria();
62
+
63
+ criteria.setAccuracy(Criteria.ACCURACY_FINE); //setAccuracyは内部では、https://stackoverflow.com/a/17874592/1709287の用にHorizontalAccuracyの設定に変換されている。
64
+
65
+ criteria.setPowerRequirement(Criteria.POWER_HIGH);
66
+
67
+ criteria.setAltitudeRequired(false);
68
+
69
+ criteria.setSpeedRequired(true);
70
+
71
+ criteria.setCostAllowed(true);
72
+
73
+ criteria.setBearingRequired(false);
74
+
75
+
76
+
77
+ //API level 9 and up
78
+
79
+ criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
80
+
81
+ criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
82
+
83
+ //criteria.setBearingAccuracy(Criteria.ACCURACY_HIGH);
84
+
85
+ //criteria.setSpeedAccuracy(Criteria.ACCURACY_HIGH);
86
+
87
+
88
+
89
+ Integer gpsFreqInMillis = 5000;
42
90
 
43
91
  Integer gpsFreqInDistance = 5; // in meters
44
92
 
45
93
 
46
94
 
47
- locationManager.addGpsStatusListener(this);
48
95
 
49
- locationManager.requestLocationUpdates(gpsFreqInMillis, gpsFreqInDistance, criteria, this, null);
50
96
 
51
- ///このようにしても、このようなエラーが出ます。
97
+ LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
52
98
 
53
- Error:(158, 24) エラー: requestLocationUpdatesに適切なメソッドが見つかりません(Integer,Integer,Criteria,GpsService,<null>)
99
+ bestProvider = locationManager.getBestProvider(criteria, true)
54
100
 
55
- メソッド LocationManager.requestLocationUpdates(String,long,float,LocationListener,Looper)は使用できません
56
101
 
57
- (引数の不一致: IntegerをStringに変換できません:)
58
102
 
59
- メソッド LocationManager.requestLocationUpdates(long,float,Criteria,LocationListener,Looper)は使用できません
103
+ locationManager.requestLocationUpdates(bestProvider,6000,1,this);
60
104
 
61
- (引数の不一致: GpsServiceをLocationListenerに変換できません:)
105
+ }
62
106
 
63
107
  ```