Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
5
5711403296
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paded
5711403296
Commits
76c859c0
Commit
76c859c0
authored
May 29, 2018
by
Paded
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix update location onChange only
parent
6f49af81
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
11 deletions
+75
-11
build_file_checksums.ser
.idea/caches/build_file_checksums.ser
+0
-0
UbonTransitDriver-app.iml___jb_tmp___
app/UbonTransitDriver-app.iml___jb_tmp___
+0
-0
TrackerService3.java
...itdriver/paded/com/ubontransitdriver/TrackerService3.java
+72
-8
build.gradle
build.gradle
+1
-1
gradle-wrapper.properties
gradle/wrapper/gradle-wrapper.properties
+2
-2
No files found.
.idea/caches/build_file_checksums.ser
View file @
76c859c0
No preview for this file type
app/UbonTransitDriver-app.iml___jb_tmp___
0 → 100644
View file @
76c859c0
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/TrackerService3.java
View file @
76c859c0
...
...
@@ -10,6 +10,7 @@ import android.os.IBinder;
import
android.os.Looper
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.util.Log
;
import
android.Manifest
;
...
...
@@ -21,7 +22,9 @@ import com.google.android.gms.common.api.Status;
import
com.google.android.gms.location.FusedLocationProviderClient
;
import
com.google.android.gms.location.Geofence
;
import
com.google.android.gms.location.GeofencingRequest
;
import
com.google.android.gms.location.LocationAvailability
;
import
com.google.android.gms.location.LocationCallback
;
import
com.google.android.gms.location.LocationListener
;
import
com.google.android.gms.location.LocationRequest
;
import
com.google.android.gms.location.LocationResult
;
import
com.google.android.gms.location.LocationServices
;
...
...
@@ -45,9 +48,10 @@ import ubontransitdriver.paded.com.ubontransitdriver.GEOFENCE.GeofenceRegistrati
public
class
TrackerService3
extends
Service
implements
GoogleApiClient
.
ConnectionCallbacks
,
GoogleApiClient
.
OnConnectionFailedListener
{
GoogleApiClient
.
OnConnectionFailedListener
,
LocationListener
{
FusedLocationProviderClient
mFusedLocationClient
;
GoogleApiClient
mGoogleApiClient
;
private
GoogleApiClient
googleApiClient
;
LocationRequest
mLocationRequest
;
String
TAG
=
"trackService"
;
private
String
user_id
;
...
...
@@ -104,7 +108,7 @@ public class TrackerService3 extends Service implements
// Log.d(TAG, "onStartCommand: "+user_id+" "+bus_id);
mFusedLocationClient
=
LocationServices
.
getFusedLocationProviderClient
(
this
);
if
(
mGoogleApiClient
!=
null
&&
mFusedLocationClient
!=
null
)
{
requestLocationUpdates
();
//
requestLocationUpdates();
}
else
{
buildGoogleApiClient
();
}
...
...
@@ -112,10 +116,20 @@ public class TrackerService3 extends Service implements
}
protected
synchronized
void
buildGoogleApiClient
()
{
// mGoogleApiClient = new GoogleApiClient.Builder(this)
// .addConnectionCallbacks(this)
// .addOnConnectionFailedListener(this)
// .addApi(LocationServices.API)
// .build();
// mGoogleApiClient.connect();
//////////////////////////////////////
// Create Google API Client instance
mGoogleApiClient
=
new
GoogleApiClient
.
Builder
(
this
)
.
addApi
(
LocationServices
.
API
)
.
addConnectionCallbacks
(
this
)
.
addOnConnectionFailedListener
(
this
)
.
addApi
(
LocationServices
.
API
)
.
build
();
mGoogleApiClient
.
connect
();
}
...
...
@@ -275,7 +289,8 @@ public class TrackerService3 extends Service implements
super
.
onDestroy
();
if
(
mFusedLocationClient
!=
null
)
{
Log
.
d
(
TAG
,
"Service Stop"
);
mFusedLocationClient
.
removeLocationUpdates
(
mLocationCallback
);
// mFusedLocationClient.removeLocationUpdates(mLocationCallback);
LocationServices
.
FusedLocationApi
.
removeLocationUpdates
(
mGoogleApiClient
,
this
);
}
}
...
...
@@ -322,7 +337,8 @@ public class TrackerService3 extends Service implements
}
;
};
...
...
@@ -346,10 +362,35 @@ public class TrackerService3 extends Service implements
@Override
public
void
onConnected
(
@Nullable
Bundle
bundle
)
{
requestLocationUpdates
();
// requestLocationUpdates();
// Log.d(TAG, "Google Api Client Connected");
// isMonitoring = true;
// // startGeofencing();
//////////////////////////////////////////////
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
)
{
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return
;
}
LocationAvailability
locationAvailability
=
LocationServices
.
FusedLocationApi
.
getLocationAvailability
(
mGoogleApiClient
);
if
(
locationAvailability
.
isLocationAvailable
())
{
// Call Location Services
Log
.
d
(
TAG
,
"Google Api Client Connected"
);
isMonitoring
=
true
;
// startGeofencing();
LocationRequest
locationRequest
=
new
LocationRequest
()
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
)
.
setInterval
(
100000
);
LocationServices
.
FusedLocationApi
.
requestLocationUpdates
(
mGoogleApiClient
,
locationRequest
,
this
);
}
else
{
// Do something when Location Provider not available
}
}
...
...
@@ -364,4 +405,27 @@ public class TrackerService3 extends Service implements
isMonitoring
=
false
;
}
@Override
public
void
onLocationChanged
(
Location
location
)
{
final
String
path
=
"active_bus/"
+
user_id
;
DatabaseReference
ref
=
FirebaseDatabase
.
getInstance
().
getReference
(
path
);
ref
.
child
(
"lat"
).
setValue
(
location
.
getLatitude
());
ref
.
child
(
"lng"
).
setValue
(
location
.
getLongitude
());
Calendar
c
=
Calendar
.
getInstance
();
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
formattedDate
=
df
.
format
(
c
.
getTime
());
ref
.
child
(
"time"
).
setValue
(
formattedDate
);
ref
.
child
(
"bus_id"
).
setValue
(
bus_id
);
ref
.
child
(
"destination"
).
setValue
(
destination
);
ref
.
child
(
"start_busstop_id"
).
setValue
(
start_busstop_id
);
ref
.
child
(
"stop_busstop_id"
).
setValue
(
stop_busstop_id
);
Log
.
d
(
TAG
,
"onLocationChanged: "
+
location
.
getLatitude
()+
" "
+
location
.
getLongitude
());
}
}
build.gradle
View file @
76c859c0
...
...
@@ -7,7 +7,7 @@ buildscript {
jcenter
()
}
dependencies
{
classpath
'com.android.tools.build:gradle:3.1.
0-alpha06
'
classpath
'com.android.tools.build:gradle:3.1.
2
'
// NOTE: Do not place your application dependencies here; they belong
...
...
gradle/wrapper/gradle-wrapper.properties
View file @
76c859c0
#
Mon Jan 15 11:01:57
ICT 2018
#
Tue May 29 16:02:46
ICT 2018
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-4.4-
rc-3-
all.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-4.4-all.zip
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment