Java Code Examples for android.content.Context#stopService()

The following examples show how to use android.content.Context#stopService() . 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: JiGuangReceiver.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    if (TextUtils.equals(intent.getAction(), JPushInterface.ACTION_MESSAGE_RECEIVED)) {
        String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
        if (!TextUtils.isEmpty(message)) {
            try {
                if (!JSONObject.NULL.equals(new JSONObject(message))) {
                    context.stopService(new Intent(context, LetvPushService.class));
                    Intent serviceIntent = new Intent(context, LetvPushService.class);
                    serviceIntent.putExtra(JPushInterface.EXTRA_MESSAGE, message);
                    context.startService(serviceIntent);
                    if (!TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_MSG_ID))) {
                        JPushInterface.reportNotificationOpened(context, bundle.getString(JPushInterface.EXTRA_MSG_ID));
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 2
Source File: ServiceManager.java    From understand-plugin-framework with Apache License 2.0 6 votes vote down vote up
/**
 * 停止某个插件Service, 当全部的插件Service都停止之后, ProxyService也会停止
 * @param targetIntent
 * @return
 */
public int stopService(Intent targetIntent) {
    ServiceInfo serviceInfo = selectPluginService(targetIntent);
    if (serviceInfo == null) {
        Log.w(TAG, "can not found service: " + targetIntent.getComponent());
        return 0;
    }
    Service service = mServiceMap.get(serviceInfo.name);
    if (service == null) {
        Log.w(TAG, "can not runnning, are you stopped it multi-times?");
        return 0;
    }
    service.onDestroy();
    mServiceMap.remove(serviceInfo.name);
    if (mServiceMap.isEmpty()) {
        // 没有Service了, 这个没有必要存在了
        Log.d(TAG, "service all stopped, stop proxy");
        Context appContext = UPFApplication.getContext();
        appContext.stopService(new Intent().setComponent(new ComponentName(appContext.getPackageName(), ProxyService.class.getName())));
    }
    return 1;
}
 
Example 3
Source File: ServiceLifecycleTest.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBindStartStopUnbind() throws InterruptedException {
    Context context = InstrumentationRegistry.getTargetContext();
    ServiceConnection connection = bindToService();
    awaitAndAssertEvents(ON_CREATE, ON_START);

    context.startService(mServiceIntent);
    // Precaution: give a chance to dispatch events
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    // still the same events
    awaitAndAssertEvents(ON_CREATE, ON_START);

    context.stopService(mServiceIntent);
    // Precaution: give a chance to dispatch events
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    // service is still bound
    awaitAndAssertEvents(ON_CREATE, ON_START);

    context.unbindService(connection);
    awaitAndAssertEvents(ON_CREATE, ON_START,
            ON_STOP, ON_DESTROY);
}
 
Example 4
Source File: HomeKeyReceiver.java    From Float-Bar with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();
	if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
		String reason = intent.getStringExtra(SYSTEM_REASON);
		if (reason != null) {
			if (reason.equals(SYSTEM_HOME_KEY)) {
				Log.e("homekey", "home键被点击");
				context.stopService(new Intent(context, DrawService.class));
			} else if (reason.equals(SYSTEM_RECENT_APPS)) {
				Log.e("homekey", "长按home键");
			}
		}
	}
}
 
Example 5
Source File: ServiceManager20.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * 停止某个插件Service, 当全部的插件Service都停止之后, ProxyService也会停止
 *
 * @param targetIntent targetIntent
 * @return int
 */
public int stopService(Intent targetIntent) {
    ServiceInfo serviceInfo = selectPluginService(targetIntent);
    if (serviceInfo == null) {
        Log.w(TAG, "can not found service: " + targetIntent.getComponent());
        return 0;
    }
    String processName3 = ProcessUtil.getProcessNameViaManager(MApplication.getInstance());
    Log.d(TAG, "3processName:" + processName3);
    Log.d(TAG, "3mServiceMap.size:" + mServiceMap.size());
    Log.d(TAG, "3mServiceMap.get(serviceInfo.name):" + serviceInfo.name);

    Service service = mServiceMap.get(serviceInfo.name);
    if (service == null) {
        Log.w(TAG, "can not runnning, are you stopped it multi-times?");
        return 0;
    }
    service.onDestroy();
    mServiceMap.remove(serviceInfo.name);
    if (mServiceMap.isEmpty()) {
        // 没有Service了, 这个没有必要存在了
        Log.d(TAG, "service all stopped, stop proxy");
        Context appContext = MApplication.getInstance();
        appContext.stopService(new Intent().setComponent(new ComponentName(appContext.getPackageName(), PluginProxyService.class.getName())));
    }
    return 1;
}
 
Example 6
Source File: PhoneStateScanner.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
static void stopAutoRegistration(Context context, boolean clearRegistration) {
    //PPApplication.logE("PhoneStateScanner.stopAutoRegistration", "xxx");

    // stop registration service
    context.stopService(new Intent(context.getApplicationContext(), MobileCellsRegistrationService.class));
    //MobileCellsRegistrationService.stop(context);

    if (clearRegistration) {
        //clearEventList();
        // set enabledAutoRegistration=false
        //PPApplication.logE("[REG] PhoneStateScanner.stopAutoRegistration", "setMobileCellsAutoRegistration(true)");
        MobileCellsRegistrationService.setMobileCellsAutoRegistration(context, true);
    }
}
 
Example 7
Source File: DialogService.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void closePipView(Context context) {
    if (context != null) {
        Intent serviceStop = new Intent();
        serviceStop.setClass(context, DialogService.class);
        context.stopService(serviceStop);
    }
}
 
Example 8
Source File: ScreenListenerService.java    From physical-web with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  Intent discoveryIntent = new Intent(context, UrlDeviceDiscoveryService.class);
  if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
    context.startService(discoveryIntent);
  } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
    context.stopService(discoveryIntent);
  }
}
 
Example 9
Source File: ServiceHelper.java    From matlog with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized void stopBackgroundServiceIfRunning(Context context) {
    boolean alreadyRunning = ServiceHelper.checkIfServiceIsRunning(context, LogcatRecordingService.class);

    log.d("Is CatlogService running: %s", alreadyRunning);

    if (alreadyRunning) {
        Intent intent = new Intent(context, LogcatRecordingService.class);
        context.stopService(intent);
    }

}
 
Example 10
Source File: BootReceiver.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SHUTDOWN)) {
        android.util.Log.d(
                "Linphone",
                "[Boot Receiver] Device is shutting down, destroying Core to unregister");
        context.stopService(
                new Intent(Intent.ACTION_MAIN).setClass(context, LinphoneService.class));
    } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
        LinphonePreferences.instance().setContext(context);
        boolean autostart = LinphonePreferences.instance().isAutoStartEnabled();
        android.util.Log.i(
                "Linphone", "[Boot Receiver] Device is starting, auto_start is " + autostart);

        if (autostart && !LinphoneService.isReady()) {
            startService(context);
        }
    } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_MY_PACKAGE_REPLACED)) {
        LinphonePreferences.instance().setContext(context);
        boolean foregroundService =
                LinphonePreferences.instance().getServiceNotificationVisibility();
        android.util.Log.i(
                "Linphone",
                "[Boot Receiver] App has been updated, foreground service is "
                        + foregroundService);

        if (foregroundService && !LinphoneService.isReady()) {
            startService(context);
        }
    }
}
 
Example 11
Source File: ServiceHelper.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public static void startOrStopCrazyLogger(Context context) {

        boolean alreadyRunning = checkIfServiceIsRunning(context, CrazyLoggerService.class);
        Intent intent = new Intent(context, CrazyLoggerService.class);

        if (!alreadyRunning) {
            context.startService(intent);
        } else {
            context.stopService(intent);
        }

    }
 
Example 12
Source File: ShutdownReceiver.java    From AndroidProgramming3e with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Intent shutdown = new Intent(context, MockWalkerService.class);
    context.stopService(shutdown);
}
 
Example 13
Source File: XMPPSession.java    From mangosta-android with Apache License 2.0 4 votes vote down vote up
public static void stopService(Context context) {
    Intent serviceIntent = new Intent(context, XMPPSessionService.class);
    serviceIntent.setPackage("com.nanoscopia.services");
    context.stopService(serviceIntent);
}
 
Example 14
Source File: Daedalus.java    From Daedalus with GNU General Public License v3.0 4 votes vote down vote up
public static void deactivateService(Context context) {
    context.startService(getServiceIntent(context).setAction(DaedalusVpnService.ACTION_DEACTIVATE));
    context.stopService(getServiceIntent(context));
}
 
Example 15
Source File: MediaPlayerService.java    From LivePlayback with Apache License 2.0 4 votes vote down vote up
public static void intentToStop(Context context) {
    context.stopService(newIntent(context));
}
 
Example 16
Source File: MyUtils.java    From SimplePomodoro-android with MIT License 4 votes vote down vote up
public static void autoStopWakelockService(Context c){
	if(isWakeLockServiceRunning()){
		c.stopService(new Intent(c, WakeLockService.class));
	}
}
 
Example 17
Source File: SocketService.java    From Android with MIT License 4 votes vote down vote up
public static void stopServer(Context context) {
    Intent intent = new Intent(context, SocketService.class);
    context.stopService(intent);
}
 
Example 18
Source File: SyncCancelAction.java    From rcloneExplorer with MIT License 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Intent syncIntent = new Intent(context, SyncService.class);
    context.stopService(syncIntent);
}
 
Example 19
Source File: UploadCancelAction.java    From rcloneExplorer with MIT License 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Intent uploadIntent = new Intent(context, UploadService.class);
    context.stopService(uploadIntent);
}
 
Example 20
Source File: ReleaseService.java    From BalloonPerformer with Apache License 2.0 4 votes vote down vote up
public static void stopService(Context context) {
    Intent intent = new Intent(context, ReleaseService.class);
    context.stopService(intent);
    // 用户想要关闭悬浮窗
    PreferenceHelper.setIsRunning(context, false);
}