Example usage for android.content ContextWrapper bindService

List of usage examples for android.content ContextWrapper bindService

Introduction

In this page you can find the example usage for android.content ContextWrapper bindService.

Prototype

@Override
    public boolean bindService(Intent service, ServiceConnection conn, int flags) 

Source Link

Usage

From source file:Main.java

private static void bindToService(Intent intent, Context context, ServiceConnection callback) {
    Context realActivity = context.getApplicationContext();
    if (realActivity == null) {
        realActivity = context;/*w  w  w . j ava 2 s. c o m*/
    }
    ContextWrapper cw = new ContextWrapper(realActivity);
    cw.startService(intent);
    cw.bindService(intent, callback, Context.BIND_AUTO_CREATE);
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

public static ServiceToken bindToService(Activity context, ServiceConnection callback) {
    Activity realActivity = context.getParent();
    if (realActivity == null) {
        realActivity = context;/*w w w  .java  2 s  .  c o m*/
    }
    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);
    }
    Log.e("Music", "Failed to bind to service");
    return null;
}

From source file:com.andrew.apollo.utils.MusicUtils.java

/**
 * @param context The {@link Context} to use
 * @param callback The {@link ServiceConnection} to use
 * @return The new instance of {@link ServiceToken}
 *//*from w w  w . ja v a  2 s  .  co m*/
public static ServiceToken bindToService(final Context context, final ServiceConnection callback) {
    Activity realActivity = ((Activity) context).getParent();
    if (realActivity == null) {
        realActivity = (Activity) context;
    }
    final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
    contextWrapper.startService(new Intent(contextWrapper, MusicPlaybackService.class));
    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;
}

From source file:jp.mixi.android.sdk.MixiContainerImpl.java

private boolean bindRemoteService(ContextWrapper context, Intent intent, ServiceConnection connection) {
    return context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
}