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