@Override public boolean bindService(Intent service, ServiceConnection conn, int flags) { return mBase.bindService(service, conn, flags); }
public static void bindService(Context context, ServiceConnection connection) { Intent intent = new Intent(context, DownloadService.class); context.startService(intent); context.bindService(intent, connection, Context.BIND_AUTO_CREATE); isRunning = true; }
public static void checkForRunningMission(Context context, String location, String name, DMChecker check) { Intent intent = new Intent(); intent.setClass(context, DownloadManagerService.class); context.bindService(intent, new ServiceConnection() { @Override public void onServiceConnected(ComponentName cname, IBinder service) { try { ((DMBinder) service).getDownloadManager().checkForRunningMission(location, name, check); } catch (Exception err) { Log.w(TAG, "checkForRunningMission() callback is defective", err); } // TODO: find a efficient way to unbind the service. This destroy the service due idle, but is started again when the user start a download. context.unbindService(this); } @Override public void onServiceDisconnected(ComponentName name) { } }, Context.BIND_AUTO_CREATE); }
public BumpMonitor(Context context) { context.bindService(new Intent(context, MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT); sensorMgr = (SensorManager) context.getSystemService(AppCompatActivity.SENSOR_SERVICE); bumpSensor = sensorMgr.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION); if (bumpSensor == null) { Log.i("BumpMonitor", "Warning: no significant motion sensor"); } else { boolean registered = sensorMgr.requestTriggerSensor(sensorListener, bumpSensor); Log.i("BumpMonitor", "Significant motion sensor registered: "+registered); } }
final Context appContext = context.getApplicationContext(); final Intent intent = new Intent(appContext, MusicService.class); appContext.startService(intent); ServiceConnection connection = new ServiceConnection() { // ... }; appContext.bindService(intent, connection, 0);
public BarometerMonitor(Context context) { prefs = new PreferenceManager(context); context.bindService(new Intent(context, MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT); sensorMgr = (SensorManager) context.getSystemService(AppCompatActivity.SENSOR_SERVICE); sensor = sensorMgr.getDefaultSensor(Sensor.TYPE_PRESSURE); if (sensor == null) { Log.i("Pressure", "Warning: no barometer sensor"); } else { sensorMgr.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } }
public AmbientLightMonitor(Context context) { prefs = new PreferenceManager(context); context.bindService(new Intent(context, MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT); sensorMgr = (SensorManager) context.getSystemService(AppCompatActivity.SENSOR_SERVICE); //noinspection RedundantCast sensor = (Sensor) sensorMgr.getDefaultSensor(Sensor.TYPE_LIGHT); if (sensor == null) { Log.i("AccelerometerFrament", "Warning: no accelerometer"); } else { sensorMgr.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } }
void bind() { Log.v(TAG, "initiating bind to authenticator type " + mAuthenticatorInfo.desc.type); Intent intent = new Intent(); intent.setAction(AccountManager.ACTION_AUTHENTICATOR_INTENT); intent.setClassName(mAuthenticatorInfo.serviceInfo.packageName, mAuthenticatorInfo.serviceInfo.name); intent.putExtra("_VA_|_user_id_", mUserId); if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE)) { Log.d(TAG, "bind attempt failed for " + toDebugString()); onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "bind failure"); } }
}}, new Consumer<Intent>() { @Override public void accept(final Intent intent) { condom.bindService(intent, SERVICE_CONNECTION, 0); }} };
public static boolean initOpenCV(String Version, final Context AppContext, final LoaderCallbackInterface Callback) { AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback); Intent intent = new Intent("org.opencv.engine.BIND"); intent.setPackage("org.opencv.engine"); if (AppContext.bindService(intent, helper.mServiceConnection, Context.BIND_AUTO_CREATE)) { return true; } else { AppContext.unbindService(helper.mServiceConnection); InstallService(AppContext, Callback); return false; } }
/** * Start bind Service */ private static void bindService() { synchronized (Command.class) { if (!IS_BIND) { Context context = Cmd.getContext(); if (context == null) { throw new NullPointerException("Context not should null. Please call Cmd.init(Context)"); } else { // Cmd service context.bindService(new Intent(context, CommandService.class), I_CONN, Context.BIND_AUTO_CREATE); IS_BIND = true; } } } }
private static void startTracking() { if (!isTracking.compareAndSet(false, true)) { return; } Context context = FacebookSdk.getApplicationContext(); if (context instanceof Application) { Application application = (Application) context; application.registerActivityLifecycleCallbacks(callbacks); context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE); } }
public boolean bindServiceAsUser(Intent service, ServiceConnection connection, int flags, VUserHandle user) { service = new Intent(service); if (user != null) { service.putExtra("_VA_|_user_id_", user.getIdentifier()); } return VirtualCore.get().getContext().bindService(service, connection, flags); }
public AccelerometerMonitor(Context context) { prefs = new PreferenceManager(context); /* * Set sensitivity value */ try { shakeThreshold = Integer.parseInt(prefs.getAccelerometerSensitivity()); } catch (Exception e) { shakeThreshold = 50; } context.bindService(new Intent(context, MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT); sensorMgr = (SensorManager) context.getSystemService(AppCompatActivity.SENSOR_SERVICE); accelerometer = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (accelerometer == null) { Log.i("AccelerometerFrament", "Warning: no accelerometer"); } else { sensorMgr.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); } }
/** * Method reserved for system use */ @Override public boolean bindService(Intent intent, ServiceConnection conn, int arg2) { this.serviceIntent = intent; application.getApplicationContext().startService(intent); return application.getApplicationContext().bindService(intent, conn, arg2); }
public boolean start() { if (running) { return false; } // Make sure that the service can handle the requested protocol version int availableVersion = NativeProtocol.getLatestAvailableProtocolVersionForService( protocolVersion); if (availableVersion == NativeProtocol.NO_PROTOCOL_AVAILABLE) { return false; } Intent intent = NativeProtocol.createPlatformServiceIntent(context); if (intent == null) { return false; } else { running = true; context.bindService(intent, this, Context.BIND_AUTO_CREATE); return true; } }
private void bindPlayServices() { try { getContext().bindService(getBindServiceIntent(), serviceConnection, Context.BIND_AUTO_CREATE); } catch (Exception e) { Log.e(LOG_TAG, "error in bindPlayServices", e); reportBillingError(Constants.BILLING_ERROR_BIND_PLAY_STORE_FAILED, e); } }
private static AttributionIdentifiers getAndroidIdViaService(Context context) { GoogleAdServiceConnection connection = new GoogleAdServiceConnection(); Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START"); intent.setPackage("com.google.android.gms"); if(context.bindService(intent, connection, Context.BIND_AUTO_CREATE)) { try { GoogleAdInfo adInfo = new GoogleAdInfo(connection.getBinder()); AttributionIdentifiers identifiers = new AttributionIdentifiers(); identifiers.androidAdvertiserId = adInfo.getAdvertiserId(); identifiers.limitTracking = adInfo.isTrackingLimited(); return identifiers; } catch (Exception exception) { Utility.logd("android_id", exception); } finally { context.unbindService(connection); } } return null; }
@Test public void testHandleMessage_doesntCrashOnBadJobData() { JobInvocation j = new JobInvocation.Builder() .setService(TestJobService.class.getName()) .setTag("tag") .setTrigger(Trigger.NOW) .build(); executionDelegator.executeJob(j); // noinspection WrongConstant verify(mockContext).bindService(intentCaptor.capture(), connCaptor.capture(), anyInt()); Intent executeReq = intentCaptor.getValue(); assertEquals(JobService.ACTION_EXECUTE, executeReq.getAction()); }
runInSeparateProcess(new TestService.Procedure() { @Override public void run(final Context context) { final Intent intent = new Intent(context, TestService.class); final ServiceConnection connection = new ServiceConnection() { @Override public void onServiceConnected(final ComponentName name, final IBinder service) {} @Override public void onServiceDisconnected(final ComponentName name) {} }; assertTrue("Test service is not properly setup.", context.bindService(intent, connection, Context.BIND_AUTO_CREATE)); context.unbindService(connection); installCondomProcess(context, new CondomOptions().setOutboundJudge(sBlockAllJudge)); withFakeSelfPackageName(new Runnable() { @Override public void run() { assertFalse(context.bindService(intent, connection, Context.BIND_AUTO_CREATE)); }}); // Block by outbound judge context.unbindService(connection); }}); // TODO: More cases