Guest User

Untitled

a guest
Jan 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. Intent i = new Intent(this, LocalisationService.class);
  2. startService(i);
  3.  
  4. public class LocalisationService extends Service {
  5.  
  6. private LocationManager locationManager;
  7. private LocationListener locationListener;
  8.  
  9. @Override
  10. public IBinder onBind(Intent intent) {
  11. // TODO Auto-generated method stub
  12. return null;
  13. }
  14.  
  15. @Override
  16. public int onStartCommand(Intent intent, int flags, int startId) {
  17. Notification notification = new Notification(R.drawable.iconsmall,
  18. "Notification text", System.currentTimeMillis());
  19. notification.flags |= Notification.FLAG_ONGOING_EVENT;
  20. Intent i = new Intent(this, RouteActivity.class);
  21.  
  22. i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
  23. | Intent.FLAG_ACTIVITY_SINGLE_TOP);
  24.  
  25. PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
  26.  
  27. notification.setLatestEventInfo(this, "Notification title",
  28. "notification message)", pi);
  29. startForeground(1337, notification);
  30. startListenLocation();
  31. return (START_NOT_STICKY);
  32. }
  33.  
  34. @Override
  35. public void onDestroy() {
  36. stopListenLocation();
  37. stopForeground(true);
  38. }
  39.  
  40. public void startListenLocation() {
  41. locationManager = (LocationManager) getApplicationContext()
  42. .getSystemService(Context.LOCATION_SERVICE);
  43. locationListener = new LocationListener() {
  44. public void onLocationChanged(Location location) {
  45. CurrentRouteManager.getSharedManager().updateWithLocation(
  46. location);
  47. }
  48.  
  49. public void onStatusChanged(String provider, int status,
  50. Bundle extras) {
  51.  
  52. }
  53.  
  54. public void onProviderEnabled(String provider) {
  55.  
  56. }
  57.  
  58. public void onProviderDisabled(String provider) {
  59.  
  60. }
  61.  
  62. };
  63. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
  64. 200, locationListener);
  65. locationManager.requestLocationUpdates(
  66. LocationManager.NETWORK_PROVIDER, 0, 200, locationListener);
  67. }
  68.  
  69. public void stopListenLocation() {
  70. locationManager.removeUpdates(locationListener);
  71. }
  72.  
  73. <activity
  74. android:name="com.wayzup.activity.RouteActivity"
  75. android:screenOrientation="portrait"
  76. android:launchMode="singleTop" >
  77. </activity>
  78.  
  79. <service android:name="com.wayzup.services.LocalisationService" >
  80. </service>
Add Comment
Please, Sign In to add comment