protected void updateUi() { 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) findViewById(R.id.wifi_state_image); wifiImg.setImageResource(isWifiReady ? R.drawable.wifi_state4 : R.drawable.wifi_state0); boolean running = FTPServerService.isRunning(); if (running) { // 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) 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); }
/** @} */ static void snooze(Context context, Alarm alarm) { final String snooze = PreferenceManager.getDefaultSharedPreferences(context) .getString(SettingsActivity.KEY_ALARM_SNOOZE, DEFAULT_SNOOZE); int snoozeMinutes = Integer.parseInt(snooze); final long snoozeTime = System.currentTimeMillis() + ((long) 1000 * 60 * snoozeMinutes); saveSnoozeAlert(context, alarm.id, snoozeTime); // Get the display time for the snooze and update the notification. final Calendar c = Calendar.getInstance(); c.setTimeInMillis(snoozeTime); String snoozeTimeStr = Alarms.formatTime(context, c); String label = alarm.getLabelOrDefault(context); // Notify the user that the alarm has been snoozed. Intent dismissIntent = new Intent(context, AlarmReceiver.class); dismissIntent.setAction(Alarms.CANCEL_SNOOZE); dismissIntent.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm); Intent openAlarm = new Intent(context, DeskClock.class); openAlarm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); openAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm); openAlarm.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.CLOCK_TAB_INDEX); NotificationManager nm = getNotificationManager(context); Notification notif = new Notification.Builder(context.getApplicationContext()) .setContentTitle(label) .setContentText( context.getResources().getString(R.string.alarm_alert_snooze_until, snoozeTimeStr)) .setSmallIcon(R.drawable.stat_notify_alarm) .setOngoing(true) .setAutoCancel(false) .setPriority(Notification.PRIORITY_MAX) .setWhen(0) .addAction( android.R.drawable.ic_menu_close_clear_cancel, context.getResources().getString(R.string.alarm_alert_dismiss_text), PendingIntent.getBroadcast(context, alarm.id, dismissIntent, 0)) .build(); notif.contentIntent = PendingIntent.getActivity(context, alarm.id, openAlarm, 0); nm.notify(alarm.id, notif); /// M: @} String displayTime = context.getString(R.string.alarm_alert_snooze_set, snoozeMinutes); // Intentionally log the snooze time for debugging. Log.v(displayTime); // Display the snooze minutes in a toast. Toast.makeText(context, displayTime, Toast.LENGTH_LONG).show(); context.stopService(new Intent(Alarms.ALARM_ALERT_ACTION)); context.stopService(new Intent("com.android.deskclock.ALARM_PHONE_LISTENER")); }
@Override public void onReceive(Context context, Intent intent) { Log.i("WifiO", "RecvTempDisable"); LogWO logg = new LogWO(context); logg.log("WifiOpti Service disabled for 5m"); SharedPreferences sett = context.getSharedPreferences("WifiOpti", 2); SharedPreferences.Editor settEditor = sett.edit(); settEditor.putBoolean("WifiOptiServiced", false); settEditor.putBoolean("WifiOptiTempDisabled", true); settEditor.commit(); // Turn off service Intent serviceIntent = new Intent(context, WifiOptiService.class); context.stopService(serviceIntent); // Schedule restart Intent alarmIntent = new Intent(context, RecvTempResume.class); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); cal.add(Calendar.MINUTE, 5); Log.d("WifiO", " -> " + cal.getTime().toString()); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent); }
public static boolean stop(Context context) { if (isRunning(context)) { Intent sepIntent = new Intent(SEP_SERVICE); return context.stopService(sepIntent); } return false; }
/** 终止服务 */ public static void stopService(/* Context context */ ) { if (true) { Context context = GOLauncherApp.getContext(); Intent i = new Intent(context, FloatWindowsService.class); context.stopService(i); } }
private void killTask(final MainListItem item) { int time = 0; if (!item.classNames.isEmpty()) { for (ClassListItem name : item.classNames) { Intent intent = new Intent(); intent.setClassName(item.processName, name.className); try { time = 1000; context.stopService(intent); } catch (SecurityException e) { Toast.makeText(context, item.label + " has been disable!", Toast.LENGTH_SHORT).show(); } } } final int sleepTime = time; Thread thread = new Thread() { public void run() { try { Thread.sleep(sleepTime); } catch (InterruptedException e) { e.printStackTrace(); } activityManager.killBackgroundProcesses(item.processName); } }; thread.start(); }
@Override public void onReceive(Context context, Intent intent) { NetState net = new NetState(context); if (net.checkInternetConnection()) // Show Net State { // Run Service Intent service1 = new Intent(context, MainService.class); context.startService(service1); Log.i("ServiceStart", "true"); } else { // Stop Service Intent service1 = new Intent(context, MainService.class); context.stopService(service1); Log.i("ServiceStop", "true"); } // Show Net state if (isAppForground(context)) { if (net.checkInternetConnection()) { Toast.makeText(context, "شبکه اینترنت متصل شد", Toast.LENGTH_LONG).show(); } else { Toast.makeText(context, "شبکه اینترنت قطع شد", Toast.LENGTH_LONG).show(); /* Intent i = new Intent(context, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); */ } } }
public void btnStop_OnClick(View view) { if (_blnActivatedViaStartup) { boolean blnAutoStartStillOn = _mainPrefs.getBoolean(_context.getString(R.string.keyAutoStart), false); if (blnAutoStartStillOn) { _context.stopService(_serviceIntent); Toast.makeText(_context, getString(R.string.stoppedButStartUpActivated), Toast.LENGTH_SHORT) .show(); } } else { if (_blnNonAutoStart) { _context.stopService(_serviceIntent); _blnNonAutoStart = false; } } }
public boolean stopClientsService() { threadInfos.clear(); allArguments.clear(); boolean stopped = context.stopService(intent); Log.i(TAG, "Trying to stop clients service: " + stopped); return stopped; }
private void stopGpsService() { if (serviceIntent != null) { Context context = getApplicationContext(); Log.d(TAG, "StopServiceIfRequired - Stopping the service"); context.stopService(serviceIntent); } }
@Override public void onReceive(Context context, Intent intent) { Log.d("News reader", "Battery low!"); // stop service Intent service = new Intent(context, NewsReaderService.class); context.stopService(service); }
@Override public void onDestroy() { super.onDestroy(); Features.showForeground = false; Intent intent = new Intent(mContext, MyService.class); mContext.stopService(intent); deselectAll(); }
@Override public void onDisabled(Context context) { Intent intent = new Intent(context.getApplicationContext(), UpdateWidgetService.class); context.stopService(intent); super.onDisabled(context); }
private static void updateLtoServiceStatus(Context context, boolean start) { Intent intent = new Intent(context, LtoService.class); if (start) { context.startService(intent); } else { context.stopService(intent); } }
public static void cancel(Context ctx) { AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); Log.d(TAG, "Timeout cancel"); am.cancel(buildIntent(ctx)); ctx.stopService(new Intent(ctx, TimeoutService.class)); }
@Override public void onDestroy() { super.onDestroy(); boolean blnAutoStartStillOn = _mainPrefs.getBoolean(_context.getString(R.string.keyAutoStart), false); if (!blnAutoStartStillOn || !_blnActivatedViaStartup) { _context.stopService(_serviceIntent); } }
public static void stopPushService() { applicationContext.stopService(new Intent(applicationContext, NotificationsService.class)); PendingIntent pintent = PendingIntent.getService( applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0); AlarmManager alarm = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE); alarm.cancel(pintent); }
public void stopService(final ServiceConnection connection) { try { Intent intent = new Intent(context, NotificationService.class); context.stopService(intent); context.unbindService(connection); } catch (Exception e) { e.printStackTrace(); } }
@Override public void onReceive(Context arg0, Intent arg1) { // TODO Auto-generated method stub cal = Calendar.getInstance(); alarm_cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); int minutes = cal.get(Calendar.MINUTE); int hour = cal.get(Calendar.HOUR_OF_DAY); whichWeek = cal.get(Calendar.DAY_OF_WEEK); String currentTime = ""; if (minutes <= 9 && minutes >= 0) { currentTime = hour + ":0" + minutes; } else { currentTime = hour + ":" + minutes; } if ("android.closeservice".equals(arg1.getAction())) { Intent closeService = new Intent("android.closeservice"); arg0.stopService(closeService); Toast.makeText(arg0, "关闭service", Toast.LENGTH_LONG).show(); } if ("android.alarm.demo.action".equals(arg1.getAction())) { alarm_cal.set(Calendar.HOUR_OF_DAY, arg1.getIntExtra("hour", 0)); alarm_cal.set(Calendar.MINUTE, arg1.getIntExtra("minute", 0)); alarm_cal.set(Calendar.SECOND, 0); week = arg1.getStringExtra("week"); message = arg1.getStringExtra("message"); System.out.println("time" + arg1.getStringExtra("time")); System.out.println("alarmreceiver" + week); // System.out.println("aaaaaa"); Intent serviceIntent = new Intent("android.start.service"); serviceIntent.putExtra("address", arg1.getStringExtra("address")); if (arg1.getIntExtra("isAbled", 0) == 1) { if (alarm_cal.getTimeInMillis() == cal.getTimeInMillis()) { if (isToday(arg0, week) || (week.equals(""))) { Intent it = new Intent(); it.setClass(arg0, NotiActivity.class); it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); arg0.startActivity(it); arg0.startService(serviceIntent); if (arg1.getIntExtra("isVirbate", 0) == 1) { Vibrator virbator = (Vibrator) arg0.getSystemService(Service.VIBRATOR_SERVICE); virbator.vibrate(60 * 10000); Toast.makeText(arg0, "virbate", Toast.LENGTH_LONG).show(); System.out.println("virbate"); } Toast.makeText(arg0, "闹钟来了", Toast.LENGTH_SHORT).show(); showNotification(arg0); } } } } }
@Override public void onDisabled(Context context) { // Enter relevant functionality for when the last widget is disabled boolean serviceRunning = ServiceStatusUtils.isServiceRunning(context, "com.zcj.wei_shi_360.service.WidgetService"); if (serviceRunning) { Intent intent = new Intent(context, WidgetService.class); context.stopService(intent); } }
public boolean onExit(View v) { try { Intent bgmusic = new Intent(context, SFMusic.class); context.stopService(bgmusic); musicThread.interrupt(); return true; } catch (Exception e) { return false; } }
public boolean stopServerService() { clients.clear(); clientsArray.clear(); boolean stopped = context.stopService(intent); if (stopped) { timer.running = false; initalUpdateCalled = false; } Log.i(C.TAG, "Trying to stop buffer service: " + stopped); return stopped; }
/** * 停止服务. * * @param ctx the ctx * @param className the class name * @return true, if successful */ public static boolean stopRunningService(Context ctx, String className) { Intent intent_service = null; boolean ret = false; try { intent_service = new Intent(ctx, Class.forName(className)); } catch (Exception e) { e.printStackTrace(); } if (intent_service != null) { ret = ctx.stopService(intent_service); } return ret; }
/** * Set whether or not precaching is enabled. If precaching is enabled, this receiver will start * the PrecacheService when it receives an intent. If precaching is disabled, any running * PrecacheService will be stopped, and this receiver will do nothing when it receives an intent. * * @param context The Context to use. * @param enabled Whether or not precaching is enabled. */ public static void setIsPrecachingEnabled(Context context, boolean enabled) { Log.v(TAG, "setIsPrecachingEnabled(%s)", enabled); Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); editor.putBoolean(PREF_IS_PRECACHING_ENABLED, enabled); editor.apply(); if (!enabled) { // Stop any running PrecacheService. If PrecacheService is not running, then this does // nothing. Intent serviceIntent = new Intent(null, null, context, PrecacheService.class); context.stopService(serviceIntent); } }
public static void stopService(Context context, String packName, String serviceName) { // "com.sst.terminaltoolservice""com.sst.tools.service.DamonMainService" ComponentName componetName = new ComponentName( // 这个是另外一个应用程序的包名 packName, serviceName // 这个参数是要启动的Activity ); Intent intent = new Intent(); intent.setComponent(componetName); context.stopService(intent); }
public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { if (WizSafeUtil.isAuthOkUser(context)) { // 인증이 완료된 단말이므로 SERVICE 를 실행한다. == 서비스 실행은 무조건 종료 후 실행 // 백그라운드에 DemonService라는 Sevice가 존재하는지 가져옴. ComponentName cn = new ComponentName(context.getPackageName(), WizSafeGetLocation.class.getName()); // 서비스 중지(재시작을 위하여 떠있는데몬 삭제, 데몬이 없을경우도 문제없이 삭제됨) boolean stopsvc = context.stopService(new Intent().setComponent(cn)); // 서비스 시작(위에서 중지 시킨 데몬을 시작시킴) ComponentName startsvc = context.startService(new Intent().setComponent(cn)); } } }
public static HttpDataService dataLocation(Context ctx) { HttpDataService data = new HttpDataService("location"); try { data.setList(true); PreyConfig.getPreyConfig(ctx).setMissing(true); Intent intent = new Intent(ctx, LocationService.class); ctx.startService(intent); boolean validLocation = false; PreyLocation lastLocation; HashMap<String, String> parametersMap = new HashMap<String, String>(); int i = 0; while (!validLocation) { lastLocation = PreyLocationManager.getInstance(ctx).getLastLocation(); if (lastLocation.isValid()) { validLocation = true; parametersMap.put("lat", Double.toString(lastLocation.getLat())); parametersMap.put("lng", Double.toString(lastLocation.getLng())); parametersMap.put("accuracy", Float.toString(lastLocation.getAccuracy())); } else { try { Thread.sleep(5000); } catch (InterruptedException e) { throw new PreyException("Thread was intrrupted. Finishing Location NotifierAction", e); } if (i > 2) { return null; } i++; } } data.addDataListAll(parametersMap); // ArrayList<HttpDataService> dataToBeSent = new ArrayList<HttpDataService>(); // dataToBeSent.add(data); // PreyWebServices.getInstance().sendPreyHttpData(ctx, dataToBeSent); ctx.stopService(intent); PreyConfig.getPreyConfig(ctx).setMissing(false); } catch (Exception e) { PreyLogger.e("Error causa:" + e.getMessage(), e); // PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx, // UtilJson.makeMapParam("get","location","failed",e.getMessage())); } return data; }
/** * 关闭管理器里面的所有 activity * * @param con */ public static void exitApp(Context con) { for (Activity ac : allActivity) { ac.finish(); } allTask = null; allActivity = null; Intent it = new Intent("com.cnsaas.fycrm.service.MainService"); con.stopService(it); // // 先清楚缓存 GenericUtil.clearnCache(); android.os.Process.killProcess(android.os.Process.myPid()); }
/** {@inheritDoc} */ @Override protected void onPostExecute(Activity target, Void result) { final Context context = target; try { mProgress.dismiss(); } catch (Exception e) { Log.e(TAG, "Error dismissing progress dialog", e); } target.finish(); // Stop the service that was protecting us context.stopService(new Intent(context, EmptyService.class)); }
public void onReceive(Context context, Intent intent) { // Make sure the user has opted in String preferencesKey = context.getString(R.string.main_prefs_key); SharedPreferences sharedPreferences = context.getSharedPreferences(preferencesKey, Context.MODE_PRIVATE); if (!sharedPreferences.getBoolean(context.getString(R.string.user_opted_in_flag), false)) { return; } // Handle the intent Intent discoveryIntent = new Intent(context, PwoDiscoveryService.class); if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { context.startService(discoveryIntent); } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { context.stopService(discoveryIntent); } }