List of usage examples for android.content Context stopService
public abstract boolean stopService(Intent service);
From source file:com.prey.actions.location.LocationUtil.java
public static PreyLocation getPreyLocationAppService(Context ctx, String method) throws Exception { PreyLocation location = null;//w w w. ja va 2 s.c o m Intent intent = new Intent(ctx, LocationService.class); try { ctx.startService(intent); boolean validLocation = false; int i = 0; while (!validLocation) { location = PreyLocationManager.getInstance(ctx).getLastLocation(); if (location.isValid()) { validLocation = true; } else { try { Thread.sleep(5000); } catch (InterruptedException e) { throw new PreyException("Thread was intrrupted. Finishing Location NotifierAction", e); } if (i > 2) { return null; } i++; } location.setMethod(method); } ctx.stopService(intent); } catch (Exception e) { Map<String, String> parms = UtilJson.makeMapParam("get", "location", "failed", e.getMessage()); PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx, parms); } finally { ctx.stopService(intent); } return location; }
From source file:in.co.recex.detainseventyfive.BroadcastRec.java
@Override public void onReceive(Context context, Intent intent) { Intent service1 = new Intent(context, NotificationGenerator.class); context.startService(service1);/*from w w w. j a v a 2s . c om*/ context.stopService(service1); }
From source file:com.readystatesoftware.android.geras.mqtt.GerasMqtt.java
public void stopService(Context context) { Intent intent = new Intent(context, GerasMqttService.class); context.stopService(intent); }
From source file:com.android.bleserver.AdvertiserFragment.java
/** * Stops BLE Advertising by stopping {@code AdvertiserService}. */// w w w . j a v a 2s. com private void stopAdvertising() { Context c = getActivity(); c.stopService(getServiceIntent(c)); mSwitch.setChecked(false); }
From source file:com.esminis.server.library.service.server.ServerNotification.java
public void hide(Context context) { getManager(context).cancel(NOTIFICATION_ID); notification = null;// ww w . j a v a2s . c om if (serviceIsRunning) { serviceIsRunning = false; context.stopService(new Intent(context, ServerNotificationService.class)); } }
From source file:com.drextended.actionhandler.action.IntentAction.java
/** * Request that a given application service be stopped * Override this method if you need specific behaviour * * @param context The Context, which generally get from view by {@link View#getContext()} * @param intent The intent to stop service, provided by {@link #getIntent(View, Context, String, Object)} *///from ww w . j a v a 2 s . co m protected void stopService(Context context, Intent intent) throws SecurityException { context.stopService(intent); }
From source file:com.nuvolect.securesuite.webserver.CrypServer.java
public static void enableServer(Context ctx, boolean serverEnabled) { m_serverEnabled = serverEnabled;//from w w w .ja v a 2 s.c o m Intent serverIntent = new Intent(ctx, WebService.class); if (serverEnabled) { Cryp.put(CConst.SERVER_ENABLED, CConst.TRUE); ctx.startService(serverIntent); // Start LAN web server } else { Cryp.put(CConst.SERVER_ENABLED, CConst.FALSE); ctx.stopService(serverIntent); // Stop LAN web server } }
From source file:net.micode.fileexplorer.ServerControlActivity.java
/** * This will be called by the static UiUpdater whenever the service has * changed state in a way that requires us to update our UI. We can't use * any myLog.l() calls in this function, because that will trigger an * endless loop of UI updates./*from ww w .j av a 2s. com*/ */ public void updateUi() { myLog.l(Log.DEBUG, "Updating UI", true); WifiManager wifiMgr = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE); int wifiState = wifiMgr.getWifiState(); WifiInfo info = wifiMgr.getConnectionInfo(); String wifiId = info != null ? info.getSSID() : null; boolean isWifiReady = FTPServerService.isWifiEnabled(); setText(R.id.wifi_state, isWifiReady ? wifiId : getString(R.string.no_wifi_hint)); ImageView wifiImg = (ImageView) mRootView.findViewById(R.id.wifi_state_image); wifiImg.setImageResource(isWifiReady ? R.drawable.wifi_state4 : R.drawable.wifi_state0); boolean running = FTPServerService.isRunning(); if (running) { myLog.l(Log.DEBUG, "updateUi: server is running", true); // Put correct text in start/stop button // Fill in wifi status and address InetAddress address = FTPServerService.getWifiIp(); if (address != null) { String port = ":" + FTPServerService.getPort(); ipText.setText( "ftp://" + address.getHostAddress() + (FTPServerService.getPort() == 21 ? "" : port)); } else { // could not get IP address, stop the service Context context = mActivity.getApplicationContext(); Intent intent = new Intent(context, FTPServerService.class); context.stopService(intent); ipText.setText(""); } } startStopButton.setEnabled(isWifiReady); TextView startStopButtonText = (TextView) mRootView.findViewById(R.id.start_stop_button_text); if (isWifiReady) { startStopButtonText.setText(running ? R.string.stop_server : R.string.start_server); startStopButtonText.setCompoundDrawablesWithIntrinsicBounds( running ? R.drawable.disconnect : R.drawable.connect, 0, 0, 0); startStopButtonText.setTextColor(running ? getResources().getColor(R.color.remote_disconnect_text) : getResources().getColor(R.color.remote_connect_text)); } else { if (FTPServerService.isRunning()) { Context context = mActivity.getApplicationContext(); Intent intent = new Intent(context, FTPServerService.class); context.stopService(intent); } startStopButtonText.setText(R.string.no_wifi); startStopButtonText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); startStopButtonText.setTextColor(Color.GRAY); } ipText.setVisibility(running ? View.VISIBLE : View.INVISIBLE); instructionText.setVisibility(running ? View.VISIBLE : View.GONE); instructionTextPre.setVisibility(running ? View.GONE : View.VISIBLE); }
From source file:com.farmerbb.taskbar.receiver.QuitReceiver.java
@Override public void onReceive(Context context, Intent intent) { Intent taskbarIntent = new Intent(context, TaskbarService.class); Intent startMenuIntent = new Intent(context, StartMenuService.class); Intent dashboardIntent = new Intent(context, DashboardService.class); Intent notificationIntent = new Intent(context, NotificationService.class); SharedPreferences pref = U.getSharedPreferences(context); pref.edit().putBoolean("taskbar_active", false).apply(); if (!LauncherHelper.getInstance().isOnHomeScreen()) { context.stopService(taskbarIntent); context.stopService(startMenuIntent); context.stopService(dashboardIntent); IconCache.getInstance(context).clearCache(); LocalBroadcastManager.getInstance(context) .sendBroadcast(new Intent("com.farmerbb.taskbar.START_MENU_DISAPPEARING")); }/*from w w w .j a va2s. c om*/ context.stopService(notificationIntent); }
From source file:com.farmerbb.taskbar.receiver.ShowHideTaskbarReceiver.java
@Override public void onReceive(Context context, Intent intent) { Intent taskbarIntent = new Intent(context, TaskbarService.class); Intent startMenuIntent = new Intent(context, StartMenuService.class); Intent dashboardIntent = new Intent(context, DashboardService.class); Intent notificationIntent = new Intent(context, NotificationService.class); SharedPreferences pref = U.getSharedPreferences(context); if (pref.getBoolean("is_hidden", false)) { pref.edit().putBoolean("is_hidden", false).apply(); context.stopService(notificationIntent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)) { Intent intent2 = new Intent(context, DummyActivity.class); intent2.putExtra("start_freeform_hack", true); intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent2); }// w ww . j a va2s . c om context.startService(taskbarIntent); context.startService(startMenuIntent); context.startService(dashboardIntent); context.startService(notificationIntent); } else { pref.edit().putBoolean("is_hidden", true).apply(); context.stopService(notificationIntent); if (!LauncherHelper.getInstance().isOnHomeScreen()) { context.stopService(taskbarIntent); context.stopService(startMenuIntent); context.stopService(dashboardIntent); IconCache.getInstance(context).clearCache(); LocalBroadcastManager.getInstance(context) .sendBroadcast(new Intent("com.farmerbb.taskbar.START_MENU_DISAPPEARING")); } context.startService(notificationIntent); } }