Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Intent i = new Intent(this, LocalisationService.class);
- startService(i);
- public class LocalisationService extends Service {
- private LocationManager locationManager;
- private LocationListener locationListener;
- @Override
- public IBinder onBind(Intent intent) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- Notification notification = new Notification(R.drawable.iconsmall,
- "Notification text", System.currentTimeMillis());
- notification.flags |= Notification.FLAG_ONGOING_EVENT;
- Intent i = new Intent(this, RouteActivity.class);
- i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
- | Intent.FLAG_ACTIVITY_SINGLE_TOP);
- PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
- notification.setLatestEventInfo(this, "Notification title",
- "notification message)", pi);
- startForeground(1337, notification);
- startListenLocation();
- return (START_NOT_STICKY);
- }
- @Override
- public void onDestroy() {
- stopListenLocation();
- stopForeground(true);
- }
- public void startListenLocation() {
- locationManager = (LocationManager) getApplicationContext()
- .getSystemService(Context.LOCATION_SERVICE);
- locationListener = new LocationListener() {
- public void onLocationChanged(Location location) {
- CurrentRouteManager.getSharedManager().updateWithLocation(
- location);
- }
- public void onStatusChanged(String provider, int status,
- Bundle extras) {
- }
- public void onProviderEnabled(String provider) {
- }
- public void onProviderDisabled(String provider) {
- }
- };
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
- 200, locationListener);
- locationManager.requestLocationUpdates(
- LocationManager.NETWORK_PROVIDER, 0, 200, locationListener);
- }
- public void stopListenLocation() {
- locationManager.removeUpdates(locationListener);
- }
- <activity
- android:name="com.wayzup.activity.RouteActivity"
- android:screenOrientation="portrait"
- android:launchMode="singleTop" >
- </activity>
- <service android:name="com.wayzup.services.LocalisationService" >
- </service>
Add Comment
Please, Sign In to add comment