android.content.Context#bindService ( )源码实例Demo

下面列出了android.content.Context#bindService ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: VIA-AI   文件: AsyncServiceHelper.java
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;
    }
}
 
源代码2 项目: FuzzDroid   文件: BytecodeLogger.java
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();
	}
}
 
源代码3 项目: SoloPi   文件: DisplayManager.java
/**
 * 开始展示数据
 */
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);

}
 
源代码4 项目: Pix-Art-Messenger   文件: BarcodeProvider.java
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;
    }
}
 
源代码5 项目: libcommon   文件: ServiceRecorder.java
/**
 * 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");
				}
			}
		}
	}
}
 
源代码6 项目: Document-Scanner   文件: AsyncServiceHelper.java
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;
    }
}
 
源代码7 项目: ml-authentication   文件: AsyncServiceHelper.java
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;
    }
}
 
源代码8 项目: AndroidAPS   文件: PumpPluginAbstract.java
@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();
}
 
源代码9 项目: FaceDetectDemo   文件: AsyncServiceHelper.java
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;
    }
}
 
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;
    }
}
 
源代码11 项目: Android-Car-duino   文件: AsyncServiceHelper.java
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;
    }
}
 
源代码12 项目: OneTapVideoDownload   文件: DownloadAdapter.java
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);
}
 
源代码13 项目: SoloPi   文件: CaseRecordManager.java
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);
}
 
源代码14 项目: AndroidAPS   文件: DanaRv2Plugin.java
@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();
}
 
源代码15 项目: Alite   文件: DownloaderClientMarshaller.java
@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;
    }
        
}
 
源代码16 项目: letv   文件: SsoHandler.java
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);
}
 
源代码17 项目: SmartGo   文件: ServiceLauncher.java
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);
    }
}
 
源代码18 项目: android-test   文件: ConnectionBase.java
/** {@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);
  }
}
 
源代码19 项目: Telegram-FOSS   文件: CustomTabsClient.java
/**
 * 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);
}
 
源代码20 项目: Telegram   文件: CustomTabsClient.java
/**
 * 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);
}
 
 方法所在类
 同类方法