Example usage for android.app NotificationManager cancel

List of usage examples for android.app NotificationManager cancel

Introduction

In this page you can find the example usage for android.app NotificationManager cancel.

Prototype

public void cancel(int id) 

Source Link

Document

Cancel a previously shown notification.

Usage

From source file:com.ncode.android.apps.schedo.service.SessionAlarmService.java

private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) {

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);
    final long currentTime = UIUtils.getCurrentTime(this);
    // If the session is already started, do not schedule system notification.
    if (currentTime > sessionStart) {
        LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart);
        return;//  w  w w  . j  a  v  a2  s  .  c  om
    }

    // By default, sets alarm to go off at 10 minutes before session start time.  If alarm
    // offset is provided, alarm is set to go off by that much time from now.
    long alarmTime;
    if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
        alarmTime = sessionStart - MILLI_TEN_MINUTES;
    } else {
        alarmTime = currentTime + alarmOffset;
    }

    LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString());

    final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class);
    // Setting data to ensure intent's uniqueness for different session start times.
    notifIntent.setData(new Uri.Builder().authority("com.ncode.android.apps.schedo")
            .path(String.valueOf(sessionStart)).build());
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart);
    LOGD(TAG, "-> Intent extra: session start " + sessionStart);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd);
    LOGD(TAG, "-> Intent extra: session end " + sessionEnd);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset);
    LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset);
    PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // Schedule an alarm to be fired to notify user of added sessions are about to begin.
    LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime);
    am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:com.saarang.samples.apps.iosched.service.SessionAlarmService.java

private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) {

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);
    final long currentTime = UIUtils.getCurrentTime(this);
    // If the session is already started, do not schedule system notification.
    if (currentTime > sessionStart) {
        LogUtils.LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart);
        return;/*from   w w w  .jav  a  2  s .co m*/
    }

    // By default, sets alarm to go off at 10 minutes before session start time.  If alarm
    // offset is provided, alarm is set to go off by that much time from now.
    long alarmTime;
    if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
        alarmTime = sessionStart - MILLI_TEN_MINUTES;
    } else {
        alarmTime = currentTime + alarmOffset;
    }

    LogUtils.LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString());

    final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class);
    // Setting data to ensure intent's uniqueness for different session start times.
    notifIntent.setData(new Uri.Builder().authority("com.saarang.samples.apps.iosched")
            .path(String.valueOf(sessionStart)).build());
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart);
    LogUtils.LOGD(TAG, "-> Intent extra: session start " + sessionStart);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd);
    LogUtils.LOGD(TAG, "-> Intent extra: session end " + sessionEnd);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset);
    LogUtils.LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset);
    PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // Schedule an alarm to be fired to notify user of added sessions are about to begin.
    LogUtils.LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime);
    am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:com.jjcamera.apps.iosched.service.SessionAlarmService.java

private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) {

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);
    final long currentTime = UIUtils.getCurrentTime(this);
    // If the session is already started, do not schedule system notification.
    if (currentTime > sessionStart) {
        LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart);
        return;/*from   w w w .  j a  v  a2s  .com*/
    }

    // By default, sets alarm to go off at 10 minutes before session start time.  If alarm
    // offset is provided, alarm is set to go off by that much time from now.
    long alarmTime;
    if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
        alarmTime = sessionStart - MILLI_TEN_MINUTES;
    } else {
        alarmTime = currentTime + alarmOffset;
    }

    LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString());

    final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class);
    // Setting data to ensure intent's uniqueness for different session start times.
    notifIntent.setData(new Uri.Builder().authority("com.jjcamera.apps.iosched")
            .path(String.valueOf(sessionStart)).build());
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart);
    LOGD(TAG, "-> Intent extra: session start " + sessionStart);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd);
    LOGD(TAG, "-> Intent extra: session end " + sessionEnd);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset);
    LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset);
    PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // Schedule an alarm to be fired to notify user of added sessions are about to begin.
    LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime);
    am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:com.teocci.utubinbg.BackgroundAudioService.java

/**
 * Initializes media sessions and receives media events
 *//*from w  w  w  .ja  va  2s.c o m*/
private void initMediaSessions() {
    // Make sure the media player will acquire a wake-lock while playing. If we don't do
    // that, the CPU might go to sleep while the song is playing, causing playback to stop.
    //
    // Remember that to use this, we have to declare the android.permission.WAKE_LOCK
    // permission in AndroidManifest.xml.
    mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);

    ComponentName eventReceiver = new ComponentName(getApplicationContext().getPackageName(),
            MediaButtonIntentReceiver.class.getName());
    PendingIntent buttonReceiverIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
            new Intent(Intent.ACTION_MEDIA_BUTTON), PendingIntent.FLAG_UPDATE_CURRENT);

    mSession = new MediaSessionCompat(getApplicationContext(), "simple player session", eventReceiver,
            buttonReceiverIntent);

    try {
        mController = new MediaControllerCompat(getApplicationContext(), mSession.getSessionToken());

        mSession.setCallback(new MediaSessionCompat.Callback() {
            @Override
            public void onPlay() {
                super.onPlay();
                buildNotification(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE));
            }

            @Override
            public void onPause() {

                super.onPause();
                pauseVideo();
                buildNotification(generateAction(android.R.drawable.ic_media_play, "Play", ACTION_PLAY));
            }

            @Override
            public void onSkipToNext() {
                super.onSkipToNext();
                if (!isStarting) {
                    playNext();
                }
                buildNotification(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE));
            }

            @Override
            public void onSkipToPrevious() {
                super.onSkipToPrevious();
                if (!isStarting) {
                    playPrevious();
                }
                buildNotification(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE));
            }

            @Override
            public void onStop() {
                super.onStop();
                stopPlayer();
                //remove notification and stop service
                NotificationManager notificationManager = (NotificationManager) getApplicationContext()
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.cancel(1);
                Intent intent = new Intent(getApplicationContext(), BackgroundAudioService.class);
                stopService(intent);
            }

            @Override
            public void onSetRating(RatingCompat rating) {
                super.onSetRating(rating);
            }
        });
    } catch (RemoteException re) {
        re.printStackTrace();
    }
}

From source file:de.qspool.clementineremote.ui.ConnectActivity.java

@Override
public void onResume() {
    super.onResume();

    // Check if we are currently connected, then open the player dialog
    if ((mPdConnect == null || !mPdConnect.isShowing()) && App.ClementineConnection != null
            && App.ClementineConnection.isConnected()) {
        showPlayerDialog();/*from ww  w  .j av a  2s  .  c  o m*/
        return;
    }

    // mDNS Discovery
    mClementineMDns = new ClementineMDnsDiscovery(mHandler);

    // Check if Autoconnect is enabled
    if (mSharedPref.getBoolean(SharedPreferencesKeys.SP_KEY_AC, false) && doAutoConnect) {
        // Post delayed, so the service has time to start
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                connect();
            }
        }, 250);

    } else {
        mClementineMDns.discoverServices();
    }
    doAutoConnect = true;

    // Remove still active notifications
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancel(ClementineMediaSessionNotification.NOTIFIFCATION_ID);
    mNotificationManager.cancel(DownloadManager.NOTIFICATION_ID_DOWNLOADS);
    mNotificationManager.cancel(DownloadManager.NOTIFICATION_ID_DOWNLOADS_FINISHED);
}

From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java

@Override
public void cancelNotifications_(JSONArray notificationIds) {

    Log.d(C.TAG, "LocalNotificationsBackend.cancelNotifications_: ");
    Editor editor = mPrefs.edit();//from w ww  .j a va 2 s .  c om
    AlarmManager am = (AlarmManager) mContext.getSystemService(Service.ALARM_SERVICE);
    NotificationManager nm = (NotificationManager) mContext.getSystemService(Service.NOTIFICATION_SERVICE);

    for (int i = 0, max = notificationIds.length(); i < max; i++) {
        int id = notificationIds.optInt(i);
        String idString = Integer.toString(id);
        PendingIntent pendingIntent = createPendingIntentForSchedule(idString);
        am.cancel(pendingIntent);
        nm.cancel(NOTIFICATION_MASK | id);
        String key = PREFS_PREFIX + idString;
        editor.remove(key);
    }

    editor.commit();
}

From source file:cc.echonet.coolmicapp.MainActivity.java

private void ClearLED() {
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancel(Constants.NOTIFICATION_ID_LED);
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java

protected void dismissNotification(String nid) {
    SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(MFPPush.PREFS_NAME,
            Context.MODE_PRIVATE);
    int countOfStoredMessages = sharedPreferences.getInt(MFPPush.PREFS_NOTIFICATION_COUNT, 0);

    if (countOfStoredMessages > 0) {
        for (int index = 1; index <= countOfStoredMessages; index++) {

            String key = MFPPush.PREFS_NOTIFICATION_MSG + index;
            try {
                String msg = sharedPreferences.getString(key, null);
                if (msg != null) {
                    JSONObject messageObject = new JSONObject(msg);
                    if (messageObject != null && !messageObject.isNull(NID)) {
                        String id = messageObject.getString(NID);
                        if (id != null && id.equals(nid)) {
                            MFPPushUtils.removeContentFromSharedPreferences(sharedPreferences, key);
                            MFPPushUtils.storeContentInSharedPreferences(sharedPreferences,
                                    MFPPush.PREFS_NOTIFICATION_COUNT, countOfStoredMessages - 1);
                            NotificationManager mNotificationManager = (NotificationManager) this
                                    .getSystemService(Context.NOTIFICATION_SERVICE);
                            mNotificationManager.cancel(messageObject.getInt(NOTIFICATIONID));
                        }//from   ww w. jav a2 s . c o m
                    }
                }
            } catch (JSONException e) {
                logger.error("MFPPushIntentService: dismissNotification() - Failed to dismiss notification.");
            }
        }
    }
}

From source file:com.nextgis.mobile.TrackerService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Log.d(MainActivity.TAG, "Received start id " + startId + ": " + intent);

    super.onStartCommand(intent, flags, startId);

    if (intent == null)
        return START_STICKY;

    String action = intent.getAction();
    if (action == null)
        return START_STICKY;

    Log.d(MainActivity.TAG, "action " + action);
    if (action.equals(ACTION_STOP)) {
        trackerLocationListener.setWritePostion(false);
        if (dbHelper != null)
            dbHelper.close();/*  w ww .ja  va  2  s  .com*/
        if (!trackerLocationListener.isWriteTrack())
            stopSelf();
    } else if (action.equals(ACTION_STOP_GPX)) {
        m_TrakAddPointHandler = null;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancel(mNotifyId);

        trackerLocationListener.StoreTrack(false);
        trackerLocationListener.setWriteTrack(false);
        if (!trackerLocationListener.isWritePostion())
            stopSelf();
    } else if (action.equals(ACTION_START)) {
        SharedPreferences prefs = getSharedPreferences(PreferencesActivity.SERVICE_PREF,
                MODE_PRIVATE | MODE_MULTI_PROCESS);
        boolean isStrarted = prefs.getBoolean(PreferencesActivity.KEY_PREF_SW_TRACK_SRV, false);

        if (isStrarted) {
            if (!trackerLocationListener.isWritePostion()) {
                trackerLocationListener.setWritePostion(true);

                dbHelper = new PositionDatabase(getApplicationContext());
                PositionDB = dbHelper.getWritableDatabase();

                long nMinDistChangeForUpdates = prefs
                        .getLong(PreferencesActivity.KEY_PREF_MIN_DIST_CHNG_UPD + "_long", 25);
                long nMinTimeBetweenUpdates = prefs.getLong(PreferencesActivity.KEY_PREF_MIN_TIME_UPD + "_long",
                        0);

                Log.d(MainActivity.TAG, "start LocationManager MinDist:" + nMinDistChangeForUpdates
                        + " MinTime:" + nMinTimeBetweenUpdates);

                Log.d(MainActivity.TAG, "start LocationManager.GPS_PROVIDER");
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, nMinTimeBetweenUpdates,
                        nMinDistChangeForUpdates, trackerLocationListener);
                Log.d(MainActivity.TAG, "start LocationManager.NETWORK_PROVIDER");
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, nMinTimeBetweenUpdates,
                        nMinDistChangeForUpdates, trackerLocationListener);
                Log.d(MainActivity.TAG, "request end");

            }
            boolean bEnergyEconomy = prefs.getBoolean(PreferencesActivity.KEY_PREF_SW_ENERGY_ECO, true);
            long nMinTimeBetweenSend = prefs.getLong(PreferencesActivity.KEY_PREF_TIME_DATASEND + "_long",
                    DateUtils.MINUTE_IN_MILLIS);
            ScheduleNextUpdate(this.getApplicationContext(), TrackerService.ACTION_START, nMinTimeBetweenSend,
                    bEnergyEconomy, isStrarted);
        }
    } else if (action.equals(ACTION_START_GPX)) {
        SharedPreferences prefs = getSharedPreferences(PreferencesActivity.SERVICE_PREF,
                MODE_PRIVATE | MODE_MULTI_PROCESS);
        boolean isStrarted_GPX = prefs.getBoolean(PreferencesActivity.KEY_PREF_SW_TRACKGPX_SRV, false);

        if (isStrarted_GPX) {
            if (!trackerLocationListener.isWriteTrack()) {
                trackerLocationListener.setWriteTrack(true);

                long nMinDistChangeForUpdates = prefs
                        .getLong(PreferencesActivity.KEY_PREF_MIN_DIST_CHNG_UPD + "_long", 25);
                long nMinTimeBetweenUpdates = prefs.getLong(PreferencesActivity.KEY_PREF_MIN_TIME_UPD + "_long",
                        0);

                Log.d(MainActivity.TAG, "start GPX LocationManager MinDist:" + nMinDistChangeForUpdates
                        + " MinTime:" + nMinTimeBetweenUpdates);

                Log.d(MainActivity.TAG, "start GPX LocationManager.GPS_PROVIDER");
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, nMinTimeBetweenUpdates,
                        nMinDistChangeForUpdates, trackerLocationListener);

                Intent resultIntent = new Intent(this, MainActivity.class);
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(this).addParentStack(MainActivity.class)
                        .addNextIntent(resultIntent);
                PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.record_start_notify)
                        .setContentTitle(getString(R.string.app_name)).setOngoing(true)
                        .setContentText(getString(R.string.gpx_recording))
                        .setContentIntent(resultPendingIntent);

                Notification noti = mBuilder.getNotification();
                //noti.flags |= Notification.FLAG_FOREGROUND_SERVICE;//Notification.FLAG_NO_CLEAR | 
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                mNotificationManager.notify(mNotifyId, noti);

            }
        }
        boolean bEnergyEconomy = prefs.getBoolean(PreferencesActivity.KEY_PREF_SW_ENERGY_ECO, true);
        long nMinTimeBetweenSend = prefs.getLong(PreferencesActivity.KEY_PREF_TIME_DATASEND + "_long",
                DateUtils.MINUTE_IN_MILLIS);
        ScheduleNextUpdate(getApplicationContext(), TrackerService.ACTION_START_GPX, nMinTimeBetweenSend,
                bEnergyEconomy, isStrarted_GPX);
    }
    return START_STICKY;
}

From source file:com.nextgis.mobile.services.TrackerService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Log.d(TAG, "Received start id " + startId + ": " + intent);

    super.onStartCommand(intent, flags, startId);

    if (intent == null)
        return START_STICKY;

    String action = intent.getAction();
    if (action == null)
        return START_STICKY;

    Log.d(TAG, "action " + action);
    if (action.equals(ACTION_STOP)) {
        trackerLocationListener.setWritePostion(false);
        if (dbHelper != null)
            dbHelper.close();/*from ww w.  j  av  a2 s.  com*/
        if (!trackerLocationListener.isWriteTrack())
            stopSelf();
    } else if (action.equals(ACTION_STOP_GPX)) {
        m_TrakAddPointHandler = null;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancel(mNotifyId);

        trackerLocationListener.StoreTrack(false);
        trackerLocationListener.setWriteTrack(false);
        if (!trackerLocationListener.isWritePostion())
            stopSelf();
    } else if (action.equals(ACTION_START)) {
        SharedPreferences prefs = getSharedPreferences(Constants.SERVICE_PREF,
                MODE_PRIVATE | MODE_MULTI_PROCESS);
        boolean isStrarted = prefs.getBoolean(Constants.KEY_PREF_SW_TRACK_SRV, false);

        if (isStrarted) {
            if (!trackerLocationListener.isWritePostion()) {
                trackerLocationListener.setWritePostion(true);

                dbHelper = new PositionDatabase(getApplicationContext());
                PositionDB = dbHelper.getWritableDatabase();

                long nMinDistChangeForUpdates = prefs.getLong(Constants.KEY_PREF_MIN_DIST_CHNG_UPD + "_long",
                        25);
                long nMinTimeBetweenUpdates = prefs.getLong(Constants.KEY_PREF_MIN_TIME_UPD + "_long", 0);

                Log.d(TAG, "start LocationManager MinDist:" + nMinDistChangeForUpdates + " MinTime:"
                        + nMinTimeBetweenUpdates);

                Log.d(TAG, "start LocationManager.GPS_PROVIDER");
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, nMinTimeBetweenUpdates,
                        nMinDistChangeForUpdates, trackerLocationListener);
                Log.d(TAG, "start LocationManager.NETWORK_PROVIDER");
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, nMinTimeBetweenUpdates,
                        nMinDistChangeForUpdates, trackerLocationListener);
                Log.d(TAG, "request end");

            }
            boolean bEnergyEconomy = prefs.getBoolean(Constants.KEY_PREF_SW_ENERGY_ECO, true);
            long nMinTimeBetweenSend = prefs.getLong(Constants.KEY_PREF_TIME_DATASEND + "_long",
                    DateUtils.MINUTE_IN_MILLIS);
            ScheduleNextUpdate(this.getApplicationContext(), TrackerService.ACTION_START, nMinTimeBetweenSend,
                    bEnergyEconomy, isStrarted);
        }
    } else if (action.equals(ACTION_START_GPX)) {
        SharedPreferences prefs = getSharedPreferences(Constants.SERVICE_PREF,
                MODE_PRIVATE | MODE_MULTI_PROCESS);
        boolean isStrarted_GPX = prefs.getBoolean(Constants.KEY_PREF_SW_TRACKGPX_SRV, false);

        if (isStrarted_GPX) {
            if (!trackerLocationListener.isWriteTrack()) {
                trackerLocationListener.setWriteTrack(true);

                long nMinDistChangeForUpdates = prefs.getLong(Constants.KEY_PREF_MIN_DIST_CHNG_UPD + "_long",
                        25);
                long nMinTimeBetweenUpdates = prefs.getLong(Constants.KEY_PREF_MIN_TIME_UPD + "_long", 0);

                Log.d(TAG, "start GPX LocationManager MinDist:" + nMinDistChangeForUpdates + " MinTime:"
                        + nMinTimeBetweenUpdates);

                Log.d(TAG, "start GPX LocationManager.GPS_PROVIDER");
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, nMinTimeBetweenUpdates,
                        nMinDistChangeForUpdates, trackerLocationListener);

                Intent resultIntent = new Intent(this, MainActivity.class);
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(this).addParentStack(MainActivity.class)
                        .addNextIntent(resultIntent);
                PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.record_start_notify)
                        .setContentTitle(getString(R.string.app_name)).setOngoing(true)
                        .setContentText(getString(R.string.gpx_recording))
                        .setContentIntent(resultPendingIntent);

                Notification noti = mBuilder.getNotification();
                //noti.flags |= Notification.FLAG_FOREGROUND_SERVICE;//Notification.FLAG_NO_CLEAR | 
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                mNotificationManager.notify(mNotifyId, noti);

            }
        }
        boolean bEnergyEconomy = prefs.getBoolean(Constants.KEY_PREF_SW_ENERGY_ECO, true);
        long nMinTimeBetweenSend = prefs.getLong(Constants.KEY_PREF_TIME_DATASEND + "_long",
                DateUtils.MINUTE_IN_MILLIS);
        ScheduleNextUpdate(getApplicationContext(), TrackerService.ACTION_START_GPX, nMinTimeBetweenSend,
                bEnergyEconomy, isStrarted_GPX);
    }
    return START_STICKY;
}