本文整理汇总了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);
}
}
示例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;
}
示例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();
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
示例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");
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
示例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);
}