Java Code Examples for android.app.Service#START_NOT_STICKY

The following examples show how to use android.app.Service#START_NOT_STICKY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Signal.java    From react-native-android-audio-streaming-aac with MIT License 8 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
   if (this.isPlaying) {
     //STATUS_PLAYING
     sendBroadcast(new Intent(Mode.PLAYING));
   } else if (this.isPreparingStarted) {
		sendBroadcast(new Intent(Mode.START_PREPARING));
	} else {
		sendBroadcast(new Intent(Mode.STARTED));
	}

	if (this.isPlaying) {
       sendBroadcast(new Intent(Mode.PLAYING));
   }
	return Service.START_NOT_STICKY;
}
 
Example 2
Source File: KioskService.java    From android-kiosk-mode with Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "Starting service 'KioskService'");
    running = true;
    ctx = this;

    // start a thread that periodically checks if your app is in the foreground
    t = new Thread(new Runnable() {
        @Override
        public void run() {
            do {
                handleKioskMode();
                try {
                    Thread.sleep(INTERVAL);
                } catch (InterruptedException e) {
                    Log.i(TAG, "Thread interrupted: 'KioskService'");
                }
            }while(running);
            stopSelf();
        }
    });

    t.start();
    return Service.START_NOT_STICKY;
}
 
Example 3
Source File: ScanService.java    From spidey with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
	this.telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

	lastScanName = intent.getStringExtra("scanname");
	lastScanLat = intent.getDoubleExtra("lat", 0.0);
	lastScanLon = intent.getDoubleExtra("lon", 0.0);
	
	db = DatabaseHelper.getInstance(getApplicationContext());

	/**
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
		startScan();
	else
		startSimpleScan();
		*/
	
	startLegacyScan();

	return Service.START_NOT_STICKY;
}
 
Example 4
Source File: DownloadService.java    From BlueBoard with Apache License 2.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null) {
        return Service.START_NOT_STICKY;
    }

    ArrayList<OkDownloadRequest> downLoadList = intent.getParcelableArrayListExtra(AcString.DOWNLOAD_LIST);

    initDownload(downLoadList);

    return Service.START_NOT_STICKY;
}
 
Example 5
Source File: FileOpsServiceBase.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int onStartCommand (Intent intent, int flags, int startId)
{
	if(ACTION_CANCEL_TASK.equals(intent.getAction()))
	{
		if(_currentTask != null)
		{
			_currentTask.cancel();
			_taskCancelled = true;
		}
		return Service.START_NOT_STICKY;
	}		
	return super.onStartCommand(intent, flags, startId);		
}
 
Example 6
Source File: ChatHeadService.java    From Android-ChatHead with Apache License 2.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
	// TODO Auto-generated method stub
	Log.d(Utils.LogTag, "ChatHeadService.onStartCommand() -> startId=" + startId);

	if(intent != null){
		Bundle bd = intent.getExtras();

		if(bd != null)
			sMsg = bd.getString(Utils.EXTRA_MSG);

		if(sMsg != null && sMsg.length() > 0){
			if(startId == Service.START_STICKY){
				new Handler().postDelayed(new Runnable() {

					@Override
					public void run() {
						// TODO Auto-generated method stub
						showMsg(sMsg);
					}
				}, 300);

			}else{
				showMsg(sMsg);
			}

		}

	}

	if(startId == Service.START_STICKY) {
		handleStart();
		return super.onStartCommand(intent, flags, startId);
	}else{
		return  Service.START_NOT_STICKY;
	}

}
 
Example 7
Source File: Signal.java    From react-native-audio-streaming with MIT License 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (this.isPlaying) {
        sendBroadcast(new Intent(Mode.PLAYING));
    } else if (this.isPreparingStarted) {
        sendBroadcast(new Intent(Mode.START_PREPARING));
    } else {
        sendBroadcast(new Intent(Mode.STARTED));
    }

    return Service.START_NOT_STICKY;
}
 
Example 8
Source File: GPTProcessService.java    From GPT with Apache License 2.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    //  这个对bind方式不起作用
    return Service.START_NOT_STICKY;
}
 
Example 9
Source File: VideoEncodingService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public int onStartCommand(Intent intent, int flags, int startId) {
    path = intent.getStringExtra("path");
    int oldAccount = currentAccount;
    currentAccount = intent.getIntExtra("currentAccount", UserConfig.selectedAccount);
    if (oldAccount != currentAccount) {
        NotificationCenter.getInstance(oldAccount).removeObserver(this, NotificationCenter.FileUploadProgressChanged);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.FileUploadProgressChanged);
    }
    boolean isGif = intent.getBooleanExtra("gif", false);
    if (path == null) {
        stopSelf();
        return Service.START_NOT_STICKY;
    }
    if (BuildVars.LOGS_ENABLED) {
        FileLog.d("start video service");
    }
    if (builder == null) {
        NotificationsController.checkOtherNotificationsChannel();
        builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext);
        builder.setSmallIcon(android.R.drawable.stat_sys_upload);
        builder.setWhen(System.currentTimeMillis());
        builder.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL);
        builder.setContentTitle(LocaleController.getString("AppName", R.string.AppName));
        if (isGif) {
            builder.setTicker(LocaleController.getString("SendingGif", R.string.SendingGif));
            builder.setContentText(LocaleController.getString("SendingGif", R.string.SendingGif));
        } else {
            builder.setTicker(LocaleController.getString("SendingVideo", R.string.SendingVideo));
            builder.setContentText(LocaleController.getString("SendingVideo", R.string.SendingVideo));
        }
    }
    currentProgress = 0;
    builder.setProgress(100, currentProgress, currentProgress == 0);
    startForeground(4, builder.build());
    NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build());
    return Service.START_NOT_STICKY;
}
 
Example 10
Source File: LocationSharingService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public int onStartCommand(Intent intent, int flags, int startId)
{
    if (getInfos().isEmpty())
    {
        stopSelf();
    }
    if (builder == null)
    {
        Intent intent2 = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
        intent2.setAction("org.tmessages.openlocations");
        intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent2, 0);

        builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext);
        builder.setWhen(System.currentTimeMillis());
        builder.setSmallIcon(R.drawable.live_loc);
        builder.setContentIntent(contentIntent);
        NotificationsController.checkOtherNotificationsChannel();
        builder.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL);
        builder.setContentTitle(LocaleController.getString("AppName", R.string.AppName));
        Intent stopIntent = new Intent(ApplicationLoader.applicationContext, StopLiveLocationReceiver.class);
        builder.addAction(0, LocaleController.getString("StopLiveLocation", R.string.StopLiveLocation), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 2, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT));
    }

    updateNotification(false);
    startForeground(6, builder.build());
    return Service.START_NOT_STICKY;
}
 
Example 11
Source File: PlayerService.java    From android-intents-broadcast-receivers with MIT License 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String title = "";
    String artist = "";

    if (intent.getParcelableExtra(MainActivity.EXTRA_SONG) != null) {
        Song song = intent.getParcelableExtra(MainActivity.EXTRA_SONG);
        title = song.getTitle();
        artist = song.getArtist();
    }

    Intent mainIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,
            REQUEST_OPEN, mainIntent, 0);

    Notification.Builder notificationBuilder = new Notification.Builder(this)
            .setSmallIcon(R.drawable.ic_queue_music_white)
            .setContentTitle(title)
            .setContentText(artist)
            .setContentIntent(pendingIntent);
    Notification notification = notificationBuilder.build();
    startForeground(11, notification);

    mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            stopSelf();
            stopForeground(true);
        }
    });
    return Service.START_NOT_STICKY;
}
 
Example 12
Source File: SteamService.java    From UpdogFarmer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (!running) {
        Log.i(TAG, "Command starting");
        final IntentFilter filter = new IntentFilter();
        filter.addAction(SKIP_INTENT);
        filter.addAction(STOP_INTENT);
        filter.addAction(PAUSE_INTENT);
        filter.addAction(RESUME_INTENT);
        registerReceiver(receiver, filter);
        start();
    }
    return Service.START_NOT_STICKY;
}
 
Example 13
Source File: GridOverlayService.java    From android-grid-wichterle with Apache License 2.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
	if(!sIsServiceRunning) {
		sIsServiceRunning = true;
		showNotification();
	}
	return Service.START_NOT_STICKY;
}
 
Example 14
Source File: UsbService.java    From UsbSerial with MIT License 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return Service.START_NOT_STICKY;
}
 
Example 15
Source File: MainProcessService.java    From GPT with Apache License 2.0 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    return Service.START_NOT_STICKY;
}
 
Example 16
Source File: BaseVpnService.java    From Maying with Apache License 2.0 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // Service of co.tgbot.peekfun should always be started explicitly
    return Service.START_NOT_STICKY;
}
 
Example 17
Source File: DesignOverlayService.java    From DesignOverlay-Android with Apache License 2.0 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return Service.START_NOT_STICKY;
}
 
Example 18
Source File: UsbService.java    From UsbSerial with MIT License 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return Service.START_NOT_STICKY;
}
 
Example 19
Source File: UsbSyncService.java    From UsbSerial with MIT License 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return Service.START_NOT_STICKY;
}
 
Example 20
Source File: UsbService.java    From SerialPortExample with MIT License 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return Service.START_NOT_STICKY;
}