當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.bindService方法代碼示例

本文整理匯總了Java中android.content.Context.bindService方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.bindService方法的具體用法?Java Context.bindService怎麽用?Java Context.bindService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.Context的用法示例。


在下文中一共展示了Context.bindService方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: AmbientLightMonitor

import android.content.Context; //導入方法依賴的package包/類
public AmbientLightMonitor(Context context) {
    prefs = new PreferenceManager(context);

    context.bindService(new Intent(context,
            MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT);

    sensorMgr = (SensorManager) context.getSystemService(Activity.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);
    }

}
 
開發者ID:guardianproject,項目名稱:haven,代碼行數:18,代碼來源:AmbientLightMonitor.java

示例2: connectSrcHandlerToPackageSync

import android.content.Context; //導入方法依賴的package包/類
/**
 * Connect handler to named package/class synchronously.
 *
 * @param srcContext is the context of the source
 * @param srcHandler is the hander to receive CONNECTED & DISCONNECTED
 *            messages
 * @param dstPackageName is the destination package name
 * @param dstClassName is the fully qualified class name (i.e. contains
 *            package name)
 *
 * @return STATUS_SUCCESSFUL on success any other value is an error.
 */
public int connectSrcHandlerToPackageSync(
        Context srcContext, Handler srcHandler, String dstPackageName, String dstClassName) {
    if (DBG) log("connect srcHandler to dst Package & class E");

    mConnection = new AsyncChannelConnection();

    /* Initialize the source information */
    mSrcContext = srcContext;
    mSrcHandler = srcHandler;
    mSrcMessenger = new Messenger(srcHandler);

    /*
     * Initialize destination information to null they will
     * be initialized when the AsyncChannelConnection#onServiceConnected
     * is called
     */
    mDstMessenger = null;

    /* Send intent to create the connection */
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClassName(dstPackageName, dstClassName);
    boolean result = srcContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    if (DBG) log("connect srcHandler to dst Package & class X result=" + result);
    return result ? STATUS_SUCCESSFUL : STATUS_BINDING_UNSUCCESSFUL;
}
 
開發者ID:jasonwang18,項目名稱:pluginMVPM,代碼行數:38,代碼來源:AsyncChannel.java

示例3: initialize

import android.content.Context; //導入方法依賴的package包/類
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();
	}
}
 
開發者ID:srasthofer,項目名稱:FuzzDroid,代碼行數:24,代碼來源:BytecodeLogger.java

示例4: initOpenCV

import android.content.Context; //導入方法依賴的package包/類
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;
    }
}
 
開發者ID:KAlO2,項目名稱:OpenCV,代碼行數:18,代碼來源:AsyncServiceHelper.java

示例5: initOpenCV

import android.content.Context; //導入方法依賴的package包/類
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;
    }
}
 
開發者ID:wblgers,項目名稱:OpenCV_Android_Plus,代碼行數:17,代碼來源:AsyncServiceHelper.java

示例6: startVoiceRecognition

import android.content.Context; //導入方法依賴的package包/類
/**
 * Start a voice search recognition.
 */
public void startVoiceRecognition(final Context context, final String languageCode) {
    final ConnectionRequest conReq = new ConnectionRequest(languageCode);
    conReq.setServiceCallback(new ServiceHelper.Callback() {

        @Override
        public void onResult(final String recognitionResult) {
            mCallback.onRecognitionResult(recognitionResult);
            context.unbindService(conReq);
        }
    });

    context.bindService(new Intent(context,
            ServiceHelper.class), conReq, Context.BIND_AUTO_CREATE);
}
 
開發者ID:MohammadAlBanna,項目名稱:Swift-Braille-Soft-keyboard,代碼行數:18,代碼來源:ServiceBridge.java

示例7: bindStartByContext

import android.content.Context; //導入方法依賴的package包/類
@Override
public void bindStartByContext(final Context context, final Runnable connectedRunnable) {
    if (FileDownloadUtils.isDownloaderProcess(context)) {
        throw new IllegalStateException("Fatal-Exception: You can't bind the " +
                "FileDownloadService in :filedownloader process.\n It's the invalid operation, " +
                "and is likely to cause unexpected problems.\n Maybe you want to use" +
                " non-separate process mode for FileDownloader, More detail about " +
                "non-separate mode, please move to wiki manually:" +
                " https://github.com/lingochamp/FileDownloader/wiki/filedownloader.properties");
    }

    if (FileDownloadLog.NEED_LOG) {
        FileDownloadLog.d(this, "bindStartByContext %s", context.getClass().getSimpleName());
    }

    Intent i = new Intent(context, serviceClass);
    if (connectedRunnable != null) {
        if (!connectedRunnableList.contains(connectedRunnable)) {
            connectedRunnableList.add(connectedRunnable);
        }
    }

    if (!BIND_CONTEXTS.contains(context)) {
        // 對稱,隻有一次remove,防止內存泄漏
        BIND_CONTEXTS.add(context);
    }

    context.bindService(i, this, Context.BIND_AUTO_CREATE);
    context.startService(i);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:BaseFileServiceUIGuard.java

示例8: isServiceSupport

import android.content.Context; //導入方法依賴的package包/類
public static boolean isServiceSupport(Context context) {
    Intent intent = ServiceTalker.getAuthServiceIntent();
    ServiceConnection serviceConnection = new EmptyServiceConnection();
    boolean binded = context.bindService(intent, serviceConnection, 1);
    context.unbindService(serviceConnection);
    return binded;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:8,代碼來源:ServiceChecker.java

示例9: connect

import android.content.Context; //導入方法依賴的package包/類
/**
 * Connects to the credential storage service, invoking the provided callback when connected.
 */
public static void connect(Context context, ConnectedCallback callback) {
    CredentialStorageConnection connector = new CredentialStorageConnection(callback);
    Log.d(LOG_TAG, connector.mConnectionId + ": before startService");
    context.startService(new Intent(context, CredentialStorageService.class));
    Log.d(LOG_TAG, connector.mConnectionId + ": before bindService");
    context.bindService(
            new Intent(context, CredentialStorageService.class),
            connector,
            Context.BIND_AUTO_CREATE);
    Log.d(LOG_TAG, connector.mConnectionId + ": after bindService");
}
 
開發者ID:openid,項目名稱:OpenYOLO-Android,代碼行數:15,代碼來源:CredentialStorageClient.java

示例10: bindCustomTabsService

import android.content.Context; //導入方法依賴的package包/類
public static boolean bindCustomTabsService(Context context, String packageName, CustomTabsServiceConnection connection) {
    Intent intent = new Intent("android.support.customtabs.action.CustomTabsService");
    if (!TextUtils.isEmpty(packageName)) {
        intent.setPackage(packageName);
    }

    return context.bindService(intent, connection, 33);
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:9,代碼來源:CustomTabsClient.java

示例11: initialize

import android.content.Context; //導入方法依賴的package包/類
/**
 * Initialize the Object.
 *
 * @param context the context
 * @return true if initialization completes correctly
 */
public boolean initialize(Context context) {
    this.context = context;
    this.preferences = PreferenceManager.getDefaultSharedPreferences(context);


    // FIXME check if this is right: Context.BIND_AUTO_CREATE kills the
    // service after closing the activity
    return context.bindService(new Intent(context, UpnpRegistryService.class), this, Context.BIND_AUTO_CREATE);
}
 
開發者ID:theopenbit,項目名稱:yaacc-code,代碼行數:16,代碼來源:UpnpClient.java

示例12: connect

import android.content.Context; //導入方法依賴的package包/類
@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;
    }

}
 
開發者ID:snoozinsquatch,項目名稱:unity-obb-downloader,代碼行數:15,代碼來源:DownloaderClientMarshaller.java

示例13: setup

import android.content.Context; //導入方法依賴的package包/類
public static LocalUpnpServer setup(Context ctx ) {
	LocalUpnpServer upnpServer = new LocalUpnpServer(ctx);
	ctx.bindService(new Intent(ctx, UpnpRegistryService.class),
			upnpServer, Context.BIND_AUTO_CREATE);		
	return upnpServer;
	
	

}
 
開發者ID:theopenbit,項目名稱:yaacc-code,代碼行數:10,代碼來源:LocalUpnpServer.java

示例14: bindService

import android.content.Context; //導入方法依賴的package包/類
/**
 * 綁定服務
 *
 * @param context 上下文
 * @param cls     服務類
 * @param conn    服務連接對象
 * @param flags   綁定選項
 *                <ul>
 *                <li>{@link Context#BIND_AUTO_CREATE}</li>
 *                <li>{@link Context#BIND_DEBUG_UNBIND}</li>
 *                <li>{@link Context#BIND_NOT_FOREGROUND}</li>
 *                <li>{@link Context#BIND_ABOVE_CLIENT}</li>
 *                <li>{@link Context#BIND_ALLOW_OOM_MANAGEMENT}</li>
 *                <li>{@link Context#BIND_WAIVE_PRIORITY}</li>
 *                </ul>
 */
public static void bindService(Context context, Class<?> cls, ServiceConnection conn, int flags) {
    Intent intent = new Intent(context, cls);
    context.bindService(intent, conn, flags);
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:21,代碼來源:ServiceUtils.java


注:本文中的android.content.Context.bindService方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。