Example usage for android.app Activity bindService

List of usage examples for android.app Activity bindService

Introduction

In this page you can find the example usage for android.app Activity bindService.

Prototype

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

Source Link

Usage

From source file:org.deviceconnect.android.manager.setting.BaseSettingFragment.java

private synchronized void bindManager() {
    if (isManagerBonded()) {
        return;/*from   www  . j  a v a  2  s .  c o  m*/
    }
    Activity activity = getActivity();
    if (activity != null) {
        Intent bindIntent = new Intent(activity, DConnectService.class);
        boolean canBind = activity.bindService(bindIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
        if (canBind) {
            onManagerBinding();
        } else {
            onCannotManagerBonded();
        }
    }
}

From source file:me.tassoevan.cordova.BackgroundPlugin.java

private void startService() {
    Activity context = cordova.getActivity();

    Intent intent = new Intent(context, ForegroundService.class);

    if (isDisabled || isBind) {
        return;/*from  w  w w  . j  a  va  2 s.co  m*/
    }

    context.bindService(intent, connection, Context.BIND_AUTO_CREATE);

    context.startService(intent);

    isBind = true;
}

From source file:com.anand.music.PlaylistFragment.java

@Override
public void onStart() {
    super.onStart();
    Activity containerActivity = getActivity();
    Intent playlistIntent = new Intent(containerActivity, MediaPlayerService.class);
    if (MediaPlayerService.mHasLaunched) {
        if (!mBound) {
            containerActivity.bindService(playlistIntent, mConnection, Context.BIND_AUTO_CREATE);
        }//from w ww  .j  ava  2  s  . c  om
    } else {
        containerActivity.startService(playlistIntent);
        containerActivity.bindService(playlistIntent, mConnection, Context.BIND_AUTO_CREATE);
    }
}

From source file:de.appplant.cordova.plugin.background.BackgroundMode.java

/**
 * Bind the activity to a background service and put them into foreground
 * state.//from ww w.java  2s.co m
 */
private void startService() {
    Activity context = cordova.getActivity();

    Intent intent = new Intent(context, ForegroundService.class);

    if (isDisabled || isBind)
        return;

    try {
        context.bindService(intent, connection, Context.BIND_AUTO_CREATE);

        fireEvent(Event.ACTIVATE, null);

        context.startService(intent);
    } catch (Exception e) {
        fireEvent(Event.FAILURE, e.getMessage());
    }

    isBind = true;
}

From source file:com.SmartDial.BackgroundMode.java

/**
 * Bind the activity to a background service and put them into foreground
 * state.//from   w  w  w. j  a va 2  s  . co  m
 */
private void startService() {
    Log.w("BackgroundMode", "startService");
    Activity context = this.cordova.getActivity();

    Intent intent = new Intent(context, ForegroundService.class);

    if (isDisabled || isBind)
        return;

    try {
        context.bindService(intent, connection, Context.BIND_AUTO_CREATE);

        fireEvent(Event.ACTIVATE, null);

        context.startService(intent);
    } catch (Exception e) {
        fireEvent(Event.FAILURE, e.getMessage());
    }

    isBind = true;
}

From source file:uk.org.openseizuredetector.OsdUtil.java

/**
 * bind an activity to to an already running server.
 *///  w ww  .  j a va 2  s.  c  o  m
public void bindToServer(Activity activity, SdServiceConnection sdServiceConnection) {
    Log.v(TAG, "bindToServer() - binding to SdServer");
    writeToSysLogFile("bindToServer() - binding to SdServer");
    Intent intent = new Intent(sdServiceConnection.mContext, SdServer.class);
    activity.bindService(intent, sdServiceConnection, Context.BIND_AUTO_CREATE);
}

From source file:com.anand.music.PlaylistFragment.java

/**
 * Launches the {@link com.jarekandshawnmusic.m.MediaPlayerService}
 * to play the requested playlist, or re-initializes an existing
 * {@link com.jarekandshawnmusic.m.MediaPlayerService} with a new playlist.
 * @param playlist the list of songs to play
 *//*w  w  w. j a  v a 2 s  . c  o m*/
public void setPlaylist(ArrayList<Integer> playlist) {
    if (mBound) {
        mMediaPlayerService.setPlaylist(playlist);
        mMediaPlayerService.play();
    } else {
        Activity containerActivity = getActivity();
        Intent playlistIntent = new Intent(containerActivity, MediaPlayerService.class);
        playlistIntent.putIntegerArrayListExtra("playlist", playlist);
        containerActivity.startService(playlistIntent);
        // We start this service and then bind to it, so we can control the playback
        // and get progress updates.
        containerActivity.bindService(playlistIntent, mConnection, Context.BIND_AUTO_CREATE);
    }
}

From source file:net.texh.cordovapluginstepcounter.CordovaStepCounter.java

@Override
public void onStart() {
    Activity activity = this.cordova.getActivity();
    SharedPreferences sharedPref = activity.getSharedPreferences(USER_DATA_PREF, Context.MODE_PRIVATE);
    Boolean pActive = this.getPedometerIsActive(sharedPref);
    if (pActive) {
        if (stepCounterIntent == null) {
            stepCounterIntent = new Intent(activity, StepCounterService.class);
            activity.startService(stepCounterIntent);
        }//  w ww. j  a va 2 s  .  c o m

        if (!bound) {
            activity.bindService(stepCounterIntent, mConnection, Context.BIND_AUTO_CREATE);
        }

    }

    super.onStart();
}

From source file:nl.eduvpn.app.service.VPNService.java

/**
 * Call this when your activity is starting up.
 *
 * @param activity The current activity to bind the service with.
 *//*from   w  ww  .ja v a  2  s .  c o  m*/
public void onCreate(@NonNull Activity activity) {
    OpenVPNService.setNotificationActivityClass(activity.getClass());
    VpnStatus.addStateListener(this);
    Intent intent = new Intent(activity, OpenVPNService.class);
    intent.putExtra(OpenVPNService.ALWAYS_SHOW_NOTIFICATION, true);
    intent.setAction(OpenVPNService.START_SERVICE);
    activity.bindService(intent, _serviceConnection, Context.BIND_AUTO_CREATE);
}

From source file:org.jboss.aerogear.android.authorization.oauth2.OAuth2AuthzModule.java

@Override
public void requestAccess(final Activity activity, final Callback<String> callback) {

    final String state = UUID.randomUUID().toString();

    final OAuth2AuthzService.AGAuthzServiceConnection connection = new OAuth2AuthzService.AGAuthzServiceConnection() {

        @Override//from ww  w. j  av a 2s .  com
        public void onServiceConnected(ComponentName className, IBinder iBinder) {
            super.onServiceConnected(className, iBinder);
            doRequestAccess(state, activity, callback, this);
        }

    };

    activity.bindService(new Intent(activity.getApplicationContext(), OAuth2AuthzService.class), connection,
            Context.BIND_AUTO_CREATE);

}