Java Code Examples for android.app.Activity#bindService()

The following examples show how to use android.app.Activity#bindService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onDeviceSelected(final BluetoothDevice device, final String name) {
    if (mConnectionProgressDialog != null) {
        mConnectionProgressDialog.setTitle(getString(R.string.prog_dialog_connect_title));
        mConnectionProgressDialog.setMessage(getString(R.string.prog_dialog_connect_message));
        mConnectionProgressDialog.show();
    }

    final Activity activity = getActivity();
    final Intent service = new Intent(activity, UpdateService.class);
    service.putExtra(UpdateService.EXTRA_DATA, device);
    updateUiForBeacons(BluetoothProfile.STATE_CONNECTED, UpdateService.LOCKED);
    activity.startService(service);
    mBounnd = true;
    activity.bindService(service, mServiceConnection, 0);
}
 
Example 2
Source File: AndroidWearPlugin.java    From cordova-androidwear with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
	super.initialize(cordova, webView);

	Log.d(TAG, "initialize");

	Activity context = cordova.getActivity();

	serviceIntent = new Intent(context, WearProviderService.class);

	Log.d(TAG, "Attempting to start service");
	context.startService(serviceIntent);

	Log.d(TAG, "Attempting to bind to service");
	context.bindService(serviceIntent, serviceConnection,
			Context.BIND_AUTO_CREATE);
}
 
Example 3
Source File: BackgroundMode.java    From cordova-plugin-background-mode with Apache License 2.0 6 votes vote down vote up
/**
 * Bind the activity to a background service and put them into foreground
 * state.
 */
private void startService()
{
    Activity context = cordova.getActivity();

    if (isDisabled || isBind)
        return;

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

    try {
        context.bindService(intent, connection, BIND_AUTO_CREATE);
        fireEvent(Event.ACTIVATE, null);
        context.startService(intent);
    } catch (Exception e) {
        fireEvent(Event.FAILURE, String.format("'%s'", e.getMessage()));
    }

    isBind = true;
}
 
Example 4
Source File: UpdateFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    // This will connect to the service only if it's already running
    Log.v(Utils.TAG, "" + getClass().getName());
    final Activity activity = getActivity();
    final Intent service = new Intent(activity, UpdateService.class);
    mBounnd = activity.bindService(service, mServiceConnection, 0);
    mGoogleApiClient.connect();
    handleSilentSignIn();
}
 
Example 5
Source File: SensonListener.java    From LLApp with Apache License 2.0 5 votes vote down vote up
public void startService(Activity activity){
    //开启服务
    Intent intent = new Intent(activity,AidlService.class);
    activity.startService(intent);
    //连接远程Service和Activity
    Intent bindIntent = new Intent(activity,AidlService.class);
    activity.bindService(bindIntent,sc,BIND_AUTO_CREATE);
}
 
Example 6
Source File: BaseSettingFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private synchronized void bindManager() {
    if (isManagerBonded()) {
        return;
    }
    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();
        }
    }
}
 
Example 7
Source File: UpdateFragment.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onStart() {
	super.onStart();

	// This will connect to the service only if it's already running
	final Activity activity = getActivity();
	final Intent service = new Intent(activity, UpdateService.class);
	mBinded = activity.bindService(service, mServiceConnection, 0);
}
 
Example 8
Source File: UpdateFragment.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onDeviceSelected(final BluetoothDevice device, final String name) {
	final Activity activity = getActivity();
	final Intent service = new Intent(activity, UpdateService.class);
	service.putExtra(UpdateService.EXTRA_DATA, device);
	activity.startService(service);
	mBinded = true;
	activity.bindService(service, mServiceConnection, 0);
}
 
Example 9
Source File: PlaylistFragment.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
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);
    }
}
 
Example 10
Source File: PlaylistFragment.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
@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);
        }
    } else {
        containerActivity.startService(playlistIntent);
        containerActivity.bindService(playlistIntent, mConnection, Context.BIND_AUTO_CREATE);
    }
}
 
Example 11
Source File: PlaylistFragment.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
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);
    }
}
 
Example 12
Source File: PlaylistFragment.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
@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);
        }
    } else {
        containerActivity.startService(playlistIntent);
        containerActivity.bindService(playlistIntent, mConnection, Context.BIND_AUTO_CREATE);
    }
}
 
Example 13
Source File: EipFragment.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private void bindOpenVpnService() {
    Activity activity = getActivity();
    if (activity == null) {
        Log.e(TAG, "activity is null when binding OpenVpn");
        return;
    }

    Intent intent = new Intent(activity, OpenVPNService.class);
    intent.setAction(OpenVPNService.START_SERVICE);
    activity.bindService(intent, openVpnConnection, Context.BIND_AUTO_CREATE);

}
 
Example 14
Source File: ActivityOverider.java    From AndroidPlugin with MIT License 4 votes vote down vote up
public static boolean overrideBindService(Activity fromAct,
        String pluginId, Intent intent, ServiceConnection conn, int flags) {
    // TODO overrideBindService
    Log.d(tag, "overrideBindService");
    return fromAct.bindService(intent, conn, flags);
}