当前位置: 首页>>代码示例>>Java>>正文


Java ServiceConnection类代码示例

本文整理汇总了Java中android.content.ServiceConnection的典型用法代码示例。如果您正苦于以下问题:Java ServiceConnection类的具体用法?Java ServiceConnection怎么用?Java ServiceConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServiceConnection类属于android.content包,在下文中一共展示了ServiceConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: b

import android.content.ServiceConnection; //导入依赖的package包/类
private static a b(Context context) throws Exception {
    try {
        context.getPackageManager().getPackageInfo("com.android.vending", 0);
        ServiceConnection bVar = new b();
        Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START");
        intent.setPackage("com.google.android.gms");
        if (context.bindService(intent, bVar, 1)) {
            try {
                c cVar = new c(bVar.a());
                a aVar = new a(cVar.a(), cVar.a(true));
                context.unbindService(bVar);
                return aVar;
            } catch (Exception e) {
                throw e;
            } catch (Throwable th) {
                context.unbindService(bVar);
            }
        } else {
            throw new IOException("Google Play connection failed");
        }
    } catch (Exception e2) {
        throw e2;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:br.java

示例2: get

import android.content.ServiceConnection; //导入依赖的package包/类
public ServiceDispatcher get(ServiceConnection c, Context context, Handler handler, int flags, int process) {
    synchronized (SERVICES_LOCKER) {
        ServiceDispatcher sd = null;
        ArrayMap<ServiceConnection, ServiceDispatcher> map = mServices.get(context);
        if (map != null) {
            sd = map.get(c);
        }
        if (sd == null) {
            sd = new ServiceDispatcher(c, context, handler, flags, process);
            if (map == null) {
                map = new ArrayMap<>();
                mServices.put(context, map);
            }
            map.put(c, sd);
        } else {
            sd.validate(context, handler);
        }
        return sd;
    }
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:21,代码来源:PluginServiceDispatcherManager.java

示例3: unbindService

import android.content.ServiceConnection; //导入依赖的package包/类
@Override
public void unbindService(ServiceConnection conn) {
    if (mLoader.mPluginObj.mInfo.getFrameworkVersion() <= 2) {
        // 仅框架版本为3及以上的才支持
        super.unbindService(conn);
        return;
    }
    // 先走一遍系统的逻辑
    try {
        super.unbindService(conn);
    } catch (Throwable e) {
        // Ignore
    }
    // 再走插件的unbindService
    // NOTE 由于不应重新调用context.unbind命令,故传进去的是false
    PluginServiceClient.unbindService(this, conn, false);
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:18,代码来源:PluginContext.java

示例4: onServiceDisconnected

import android.content.ServiceConnection; //导入依赖的package包/类
@Override
public void onServiceDisconnected(ComponentName componentName) {
    Log.i(TAG, "onServiceDisconnected disconnected!");
    mPluginManager = null;

    Iterator<WeakReference<ServiceConnection>> iterator = sServiceConnection.iterator();
    while (iterator.hasNext()) {
        WeakReference<ServiceConnection> wsc = iterator.next();
        ServiceConnection sc = wsc != null ? wsc.get() : null;
        if (sc != null) {
            sc.onServiceDisconnected(componentName);
        } else {
            iterator.remove();
        }
    }
    //服务连接断开,需要重新连接。
    connectToService();
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:19,代码来源:PluginManager.java

示例5: isServiceSupport

import android.content.ServiceConnection; //导入依赖的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

示例6: getDelegate

import android.content.ServiceConnection; //导入依赖的package包/类
public static IServiceConnection getDelegate(Context context, ServiceConnection connection,int flags) {
    IServiceConnection sd = null;
    if (connection == null) {
        throw new IllegalArgumentException("connection is null");
    }
    try {
        Object activityThread = ActivityThread.currentActivityThread.call();
        Object loadApk = ContextImpl.mPackageInfo.get(VirtualCore.get().getContext());
        Handler handler = ActivityThread.getHandler.call(activityThread);
        sd = LoadedApk.getServiceDispatcher.call(loadApk, connection, context, handler, flags);
    } catch (Exception e) {
        Log.e("ConnectionDelegate", "getServiceDispatcher", e);
    }
    if (sd == null) {
        throw new RuntimeException("Not supported in system context");
    }
    return getDelegate(sd);
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:19,代码来源:ServiceConnectionDelegate.java

示例7: bindToService

import android.content.ServiceConnection; //导入依赖的package包/类
public static ServiceToken bindToService(Activity context,
                                         ServiceConnection callback) {
    Activity realActivity = context.getParent();
    if (realActivity == null) {
        realActivity = context;
    }
    ContextWrapper cw = new ContextWrapper(realActivity);
    cw.startService(new Intent(cw, MediaPlaybackService.class));
    ServiceBinder sb = new ServiceBinder(callback);
    if (cw.bindService(
            (new Intent()).setClass(cw, MediaPlaybackService.class), sb, 0)) {
        sConnectionMap.put(cw, sb);
        return new ServiceToken(cw);
    }
    return null;
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:17,代码来源:MusicUtils.java

示例8: bindToService

import android.content.ServiceConnection; //导入依赖的package包/类
/**
 * @param context  The {@link Context} to use
 * @param callback The {@link ServiceConnection} to use
 * @return The new instance of {@link ServiceToken}
 */
public static ServiceToken bindToService(final Context context, final ServiceConnection callback) {
    ContextWrapper contextWrapper = new ContextWrapper(context);
    ServiceBinder binder = new ServiceBinder(callback);
    Intent intent = new Intent().setClass(contextWrapper, UploadService.class);

    if (contextWrapper.bindService(intent, binder, 0)) {
        mConnectionMap.put(contextWrapper, binder);
        return new ServiceToken(contextWrapper);
    }

    Logger.d(TAG, "bindToService, count: " + mConnectionMap.size());
    return null;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:19,代码来源:UploadUtils.java

示例9: bindToServiceWithoutStart

import android.content.ServiceConnection; //导入依赖的package包/类
public static ServiceToken bindToServiceWithoutStart(final Activity realActivity, final ServiceConnection callback) {
    final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
    final ServiceBinder binder = new ServiceBinder(callback);

    if (contextWrapper.bindService(new Intent().setClass(contextWrapper, MusicPlaybackService.class), binder, 0)) {
        mConnectionMap.put(contextWrapper, binder);
        return new ServiceToken(contextWrapper);
    }

    return null;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:12,代码来源:MusicUtils.java

示例10: bindService

import android.content.ServiceConnection; //导入依赖的package包/类
@Override public boolean bindService(final Intent intent, final ServiceConnection conn, final int flags) {
	final boolean result = mCondom.proceed(OutboundType.BIND_SERVICE, intent, Boolean.FALSE, new CondomCore.WrappedValueProcedure<Boolean>() { @Override public Boolean proceed() {
		return CondomContext.super.bindService(intent, conn, flags);
	}});
	if (result) mCondom.logIfOutboundPass(TAG, intent, CondomCore.getTargetPackage(intent), CondomCore.CondomEvent.BIND_PASS);
	return result;
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:8,代码来源:CondomContext.java

示例11: disconnect

import android.content.ServiceConnection; //导入依赖的package包/类
private void disconnect(final ServiceConnection serviceConnection) {
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            synchronized (ChidoriClient.this) {
                try {
                    if (ApplicationHolder.getAppContext() != null && serviceConnection != null) {
                        ApplicationHolder.getAppContext().unbindService(serviceConnection);
                    }
                } catch (Exception e) {
                }
            }
        }
    }, FIVE_MINUTES);
}
 
开发者ID:kymjs,项目名称:Chidori,代码行数:16,代码来源:ChidoriClient.java

示例12: checksLocationReceiverIsUpWhenServiceStarted

import android.content.ServiceConnection; //导入依赖的package包/类
@Test
public void checksLocationReceiverIsUpWhenServiceStarted() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);

  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);

  assertLocationReceiverRegistered(boundService);
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:13,代码来源:TelemetryServiceTest.java

示例13: checksTelemetryReceiverIsUpWhenServiceStarted

import android.content.ServiceConnection; //导入依赖的package包/类
@Test
public void checksTelemetryReceiverIsUpWhenServiceStarted() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);

  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);

  assertTelemetryReceiverRegistered(boundService);
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:13,代码来源:TelemetryServiceTest.java

示例14: checksLocationReceiverIsDownWhenServiceStopped

import android.content.ServiceConnection; //导入依赖的package包/类
@Test
public void checksLocationReceiverIsDownWhenServiceStopped() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);
  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);

  stopService(serviceIntent, boundService);
  waitUntilServiceIsDestroyed();

  assertLocationReceiverNotRegistered(boundService);
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:15,代码来源:TelemetryServiceTest.java

示例15: checksTelemetryReceiverIsDownWhenServiceStopped

import android.content.ServiceConnection; //导入依赖的package包/类
@Test
public void checksTelemetryReceiverIsDownWhenServiceStopped() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);
  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);

  stopService(serviceIntent, boundService);
  waitUntilServiceIsDestroyed();

  assertTelemetryReceiverNotRegistered(boundService);
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:15,代码来源:TelemetryServiceTest.java


注:本文中的android.content.ServiceConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。