Java Code Examples for android.content.Context#bindService()
The following examples show how to use
android.content.Context#bindService() .
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: AsyncServiceHelper.java From ml-authentication with Apache License 2.0 | 6 votes |
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; } }
Example 2
Source File: AsyncServiceHelper.java From Android-Car-duino with GNU General Public License v2.0 | 6 votes |
public static boolean initOpenCV(String Version, final Context AppContext, final LoaderCallbackInterface Callback) { AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback); if (AppContext.bindService(new Intent("org.opencv.engine.BIND"), helper.mServiceConnection, Context.BIND_AUTO_CREATE)) { return true; } else { AppContext.unbindService(helper.mServiceConnection); InstallService(AppContext, Callback); return false; } }
Example 3
Source File: AsyncServiceHelper.java From OpenCV-Android-Object-Detection with MIT License | 6 votes |
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; } }
Example 4
Source File: AsyncServiceHelper.java From FaceDetectDemo with Apache License 2.0 | 6 votes |
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; } }
Example 5
Source File: PumpPluginAbstract.java From AndroidAPS with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void onStart() { super.onStart(); Context context = MainApp.instance().getApplicationContext(); Intent intent = new Intent(context, getServiceClass()); context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE); serviceRunning = true; disposable.add(RxBus.INSTANCE .toObservable(EventAppExit.class) .observeOn(Schedulers.io()) .subscribe(event -> { MainApp.instance().getApplicationContext().unbindService(serviceConnection); }, FabricPrivacy::logException) ); onStartCustomActions(); }
Example 6
Source File: AsyncServiceHelper.java From VIA-AI with MIT License | 6 votes |
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; } }
Example 7
Source File: AsyncServiceHelper.java From Document-Scanner with GNU General Public License v3.0 | 6 votes |
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; } }
Example 8
Source File: ServiceRecorder.java From libcommon with Apache License 2.0 | 6 votes |
/** * Bind client to camera connection service */ private void doBindService() { if (DEBUG) Log.v(TAG, "doBindService:"); final Context context = mWeakContext.get(); if (context != null) { synchronized (mServiceSync) { if ((mState == STATE_UNINITIALIZED) && (mService == null)) { mState = STATE_BINDING; final Intent intent = createServiceIntent(context); if (DEBUG) Log.v(TAG, "call Context#bindService"); final boolean result = context.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); if (!result) { mState = STATE_UNINITIALIZED; Log.w(TAG, "failed to bindService"); } } } } }
Example 9
Source File: BarcodeProvider.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
private boolean connectAndWait() { Intent intent = new Intent(getContext(), XmppConnectionService.class); intent.setAction(this.getClass().getSimpleName()); Context context = getContext(); if (context != null) { synchronized (this) { if (mXmppConnectionService == null && !mBindingInProcess) { Log.d(Config.LOGTAG, "calling to bind service"); context.bindService(intent, this, Context.BIND_AUTO_CREATE); this.mBindingInProcess = true; } } try { waitForService(); return true; } catch (InterruptedException e) { return false; } } else { Log.d(Config.LOGTAG, "context was null"); return false; } }
Example 10
Source File: DisplayManager.java From SoloPi with Apache License 2.0 | 6 votes |
/** * 开始展示数据 */ private void start() { connection = new DisplayConnection(this); Context context = LauncherApplication.getContext(); injectorService = LauncherApplication.getInstance().findServiceByName(InjectorService.class.getName()); runningFlag = true; context.bindService(new Intent(context, FloatWinService.class), connection, Context.BIND_AUTO_CREATE); // 定时更新 executorService.schedule(new Runnable() { @Override public void run() { // 如果还在运行 if (runningFlag) { executorService.schedule(this, 500, TimeUnit.MILLISECONDS); } updateDisplayInfo(); } }, 500, TimeUnit.MILLISECONDS); }
Example 11
Source File: BytecodeLogger.java From FuzzDroid with Apache License 2.0 | 6 votes |
public static void initialize(final Context context) { // Start the service in its own thread to avoid an ANR if (tracingService == null) { Thread initThread = new Thread() { @Override public void run() { if (tracingService == null) { Log.i(SharedClassesSettings.TAG, "Binding to tracing service..."); Intent serviceIntent = new Intent(context, TracingService.class); serviceIntent.setAction(TracingService.ACTION_NULL); context.startService(serviceIntent); if (context.bindService(serviceIntent, tracingConnection, Context.BIND_AUTO_CREATE)) Log.i(SharedClassesSettings.TAG, "Tracing service bound."); else Log.i(SharedClassesSettings.TAG, "bindService() returned false."); } } }; initThread.start(); } }
Example 12
Source File: DanaRv2Plugin.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void onStart() { Context context = MainApp.instance().getApplicationContext(); Intent intent = new Intent(context, DanaRv2ExecutionService.class); context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); disposable.add(RxBus.INSTANCE .toObservable(EventAppExit.class) .observeOn(Schedulers.io()) .subscribe(event -> { MainApp.instance().getApplicationContext().unbindService(mConnection); }, FabricPrivacy::logException) ); super.onStart(); }
Example 13
Source File: DownloaderClientMarshaller.java From Alite with GNU General Public License v3.0 | 5 votes |
@Override public void connect(Context c) { mContext = c; Intent bindIntent = new Intent(c, mDownloaderServiceClass); bindIntent.putExtra(PARAM_MESSENGER, mMessenger); if ( !c.bindService(bindIntent, mConnection, Context.BIND_DEBUG_UNBIND) ) { if ( Constants.LOGVV ) { Log.d(Constants.TAG, "Service Unbound"); } } else { mBound = true; } }
Example 14
Source File: SsoHandler.java From letv with Apache License 2.0 | 5 votes |
private boolean bindRemoteSSOService(Context context) { if (!isWeiboAppInstalled()) { return false; } String pkgName = this.mWeiboInfo.getPackageName(); Intent intent = new Intent(DEFAULT_WEIBO_REMOTE_SSO_SERVICE_NAME); intent.setPackage(pkgName); return context.bindService(intent, this.mConnection, 1); }
Example 15
Source File: ServiceLauncher.java From SmartGo with Apache License 2.0 | 5 votes |
protected void startService(final Context context,final Intent intent){ final ServiceConnection connection = mServiceConnectionBox.get(); if(connection != null){ context.bindService(intent,connection, mFlag); }else { context.startService(intent); } }
Example 16
Source File: CaseRecordManager.java From SoloPi with Apache License 2.0 | 5 votes |
public void onCreate(Context context) { LogUtil.i(TAG, "onCreate"); LauncherApplication application = LauncherApplication.getInstance(); eventService = application.findServiceByName(EventService.class.getName()); operationService = application.findServiceByName(OperationService.class.getName()); injectorService = application.findServiceByName(InjectorService.class.getName()); highLightService = application.findServiceByName(HighLightService.class.getName()); operationStepService = application.findServiceByName(OperationStepService.class.getName()); injectorService.register(this); // 启动CmdHandler cmdExecutor = Executors.newSingleThreadScheduledExecutor(); windowManager = (WindowManager) LauncherApplication.getInstance().getSystemService(Context.WINDOW_SERVICE); // 获取截图服务 captureService = application.findServiceByName(ScreenCaptureService.class.getName()); PermissionUtil.grantHighPrivilegePermission(LauncherApplication.getContext()); currentRecordId = StringUtil.generateRandomString(10); setServiceToNormalMode(); // 启动悬浮窗 connection = new RecordFloatConnection(this); listener = new FloatClickListener(this); stopListener = new FloatStopListener(); context.bindService(new Intent(context, FloatWinService.class), connection, Context.BIND_AUTO_CREATE); }
Example 17
Source File: DownloadAdapter.java From OneTapVideoDownload with GNU General Public License v3.0 | 5 votes |
DownloadAdapter(Context context) { mContext = context; mSelectedItems = new SparseArray<>(); context.startService(DownloadManager.getActionStartService()); Intent mIntent = new Intent(context, DownloadManager.class); context.bindService(mIntent, mConnection, Context.BIND_ABOVE_CLIENT); }
Example 18
Source File: ConnectionBase.java From android-test with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void connect(Context context) { Intent intent = new Intent(serviceName); intent.setPackage(servicePackage); if (!context.bindService(intent, connection, Service.BIND_AUTO_CREATE)) { throw new RuntimeException("Cannot connect to " + serviceName); } }
Example 19
Source File: CustomTabsClient.java From Telegram with GNU General Public License v2.0 | 3 votes |
/** * Bind to a {@link CustomTabsService} using the given package name and * {@link ServiceConnection}. * @param context {@link Context} to use while calling * {@link Context#bindService(Intent, ServiceConnection, int)} * @param packageName Package name to set on the {@link Intent} for binding. * @param connection {@link CustomTabsServiceConnection} to use when binding. This will * return a {@link CustomTabsClient} on * {@link CustomTabsServiceConnection * #onCustomTabsServiceConnected(ComponentName, CustomTabsClient)} * @return Whether the binding was successful. */ public static boolean bindCustomTabsService(Context context, String packageName, CustomTabsServiceConnection connection) { Intent intent = new Intent(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION); if (!TextUtils.isEmpty(packageName)) intent.setPackage(packageName); return context.bindService(intent, connection, Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY); }
Example 20
Source File: CustomTabsClient.java From Telegram-FOSS with GNU General Public License v2.0 | 3 votes |
/** * Bind to a {@link CustomTabsService} using the given package name and * {@link ServiceConnection}. * @param context {@link Context} to use while calling * {@link Context#bindService(Intent, ServiceConnection, int)} * @param packageName Package name to set on the {@link Intent} for binding. * @param connection {@link CustomTabsServiceConnection} to use when binding. This will * return a {@link CustomTabsClient} on * {@link CustomTabsServiceConnection * #onCustomTabsServiceConnected(ComponentName, CustomTabsClient)} * @return Whether the binding was successful. */ public static boolean bindCustomTabsService(Context context, String packageName, CustomTabsServiceConnection connection) { Intent intent = new Intent(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION); if (!TextUtils.isEmpty(packageName)) intent.setPackage(packageName); return context.bindService(intent, connection, Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY); }