Example usage for android.content Context BIND_AUTO_CREATE

List of usage examples for android.content Context BIND_AUTO_CREATE

Introduction

In this page you can find the example usage for android.content Context BIND_AUTO_CREATE.

Prototype

int BIND_AUTO_CREATE

To view the source code for android.content Context BIND_AUTO_CREATE.

Click Source Link

Document

Flag for #bindService : automatically create the service as long as the binding exists.

Usage

From source file:com.zentri.zentri_ble_command_demo.MainActivity.java

@Override
protected void onStart() {
    super.onStart();

    mDeviceList.clear();/*from   ww w  .j  a v  a 2  s.c o m*/
    mConnected = false;
    mConnecting = false;

    Intent intent = new Intent(this, ZentriOSBLEService.class);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

    mLocalBroadcastManager.registerReceiver(mBroadcastReceiver, mReceiverIntentFilter);
}

From source file:com.SecUpwN.AIMSICD.activities.MapViewerOsmDroid.java

@Override
public void onResume() {
    super.onResume();
    setUpMapIfNeeded();/* www  . j av a 2 s.  c  o m*/

    prefs = this.getSharedPreferences(AimsicdService.SHARED_PREFERENCES_BASENAME, 0);
    prefs.registerOnSharedPreferenceChangeListener(this);

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter(updateOpenCellIDMarkers));

    if (!mBound) {
        // Bind to LocalService
        Intent intent = new Intent(mContext, AimsicdService.class);
        mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    }

    loadPreferences();
    loadEntries();

    if (mCompassOverlay != null) {
        mCompassOverlay.enableCompass();
    }

    if (mMyLocationOverlay != null) {
        mMyLocationOverlay.enableMyLocation();
    }
}

From source file:com.precisosol.llgeofence.GeofencePlugin.java

@Override
public PluginResult execute(String action, JSONArray data, String callback) {
    Looper.myLooper().prepare();/*w w w  . j  a v a2  s  .c  o m*/
    PluginResult result = null;
    if (action.equalsIgnoreCase(INITIALIZE_SERVICE)) {
        try {

            receiver = new GeofenceReceiver();
            ctx.registerReceiver(receiver, new IntentFilter(GEOFENCE_FIRED));
            ctx.registerReceiver(receiver, new IntentFilter(AUTH_SUCCESS));
            ctx.registerReceiver(receiver, new IntentFilter(AUTH_FAILURE));
            // create our ServiceConnection
            serviceConnection = new ServiceConnection() {

                public void onServiceConnected(ComponentName name, IBinder service) {
                    mService = ((GeofenceService.ServiceBinder) service).getService();
                    mService.setConsumerKeyAndSecret(CONSUMER_KEY, CONSUMER_SECRET);
                    mService.setAuthorizationActions(AUTH_SUCCESS, AUTH_FAILURE, GeofenceReceiver.class);
                    mService.authorize();
                    mService.enable();

                }

                public void onServiceDisconnected(ComponentName name) {
                    // geofences still persist
                    mService = null;
                }

            };

            if (!(ctx.bindService(new Intent(ctx, GeofenceService.class), serviceConnection,
                    Context.BIND_AUTO_CREATE))) {
                Log.w(LOG, "Failed to bind to GeofenceService");
            }

            result = new PluginResult(PluginResult.Status.OK, "Service start signal sent.");
        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }

    } else if (action.equalsIgnoreCase(CREATE_GEOFENCE)) {

        try {
            int externalIdentifier = data.getInt(0); //identifier to identify the related object internally
            double latitude = data.getDouble(1);
            double longitude = data.getDouble(2);
            float radius = (float) data.getDouble(3);
            int crossingType = data.getInt(4);
            Geofence g = AddGeofence(latitude, longitude, radius, crossingType);
            org.yajl.JSONObject tmp = new org.yajl.JSONObject(g);
            tmp.append("EID", externalIdentifier);
            String str = tmp.toString();
            tmp = null;
            Log.d("Service_Output", str);
            JSONObject resultobject = new JSONObject(str);
            str = null;
            result = new PluginResult(PluginResult.Status.OK, resultobject);

        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }

    } else if (action.equalsIgnoreCase(DELETE_GEOFENCE)) {
        try {
            long id = data.getLong(0);
            DeleteGeofence(id);
            result = new PluginResult(PluginResult.Status.OK, "Geofence deleted successfully.");
        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }

    } else if (action.equalsIgnoreCase(DELETE_ALL_GEOFENCES)) {
        try {
            DeleteAllGeofences();
            result = new PluginResult(PluginResult.Status.OK, "Geofences deleted successfully.");
        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }
    } else if (action.equalsIgnoreCase(FIND_GEOFENCE)) {
        try {
            long id = data.getLong(0);
            Geofence g = FindGeofence(id);
            org.yajl.JSONObject tmp = new org.yajl.JSONObject(g);
            String str = tmp.toString();
            tmp = null;
            Log.d("Service_Output", str);
            JSONObject resultobject = new JSONObject(str);
            str = null;
            result = new PluginResult(PluginResult.Status.OK, resultobject);
        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }
    } else if (action.equalsIgnoreCase(GET_ALL_GEOFENCES)) {
        try {
            ArrayList<Geofence> geofences = GetAllGeofences();
            org.yajl.JSONArray tmp = new org.yajl.JSONArray(geofences);
            String str = tmp.toString();
            tmp = null;
            Log.d("Service_Output", str);
            JSONArray resultobject = new JSONArray(str);
            str = null;
            result = new PluginResult(PluginResult.Status.OK, resultobject);

        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }
    } else if (action.equalsIgnoreCase(GET_CURRENT_LOCATION)) {
        try {
            if (mService != null) {
                Thread.sleep(5000);
                Location loc = location;
                org.yajl.JSONObject obj = new org.yajl.JSONObject(loc);
                JSONObject resultobject = new JSONObject(obj.toString());
                result = new PluginResult(PluginResult.Status.OK, resultobject);
            } else {
                result = new PluginResult(PluginResult.Status.ERROR, "Service not running.");
            }
        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }
    } else if (action.equalsIgnoreCase(GET_LAST_KNOWN_LOCATION)) {
        try {
            if (mService != null) {
                Location loc = mService.getLastKnownLocation();
                org.yajl.JSONObject obj = new org.yajl.JSONObject(loc);
                JSONObject resultobject = new JSONObject(obj.toString());
                result = new PluginResult(PluginResult.Status.OK, resultobject);
            }
        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }
    } else if (action.equalsIgnoreCase(SET_CALLBACKS)) {
        try {
            AUTH_SUCCESS_CALLBACK = data.getString(0);
            AUTH_FAILURE_CALLBACK = data.getString(1);
            GEOFENCE_ENTRY_CALLBACK = data.getString(2);
            GEOFENCE_EXIT_CALLBACK = data.getString(3);
            SERVICE_FAILURE_CALLBACK = data.getString(4);
            result = new PluginResult(Status.OK, "Callbacks setup Successfully.");
        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }
    } else if (action.equalsIgnoreCase(ENABLE)) {
        try {
            mService.enable();
            result = new PluginResult(Status.OK, "Service Enabled Successfully.");
        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }
    } else if (action.equalsIgnoreCase(DISABLE)) {
        try {
            mService.disable();
            result = new PluginResult(Status.OK, "Service Disabled Successfully.");
        } catch (Exception e) {
            result = new PluginResult(Status.ERROR, e.getMessage());
        }
    }

    return result;
}

From source file:com.github.chenxiaolong.dualbootpatcher.switcher.MbtoolTaskOutputFragment.java

@Override
public void onStart() {
    super.onStart();

    // Create terminal
    mSession = new TermSession();
    // We don't care about any input because this is kind of a "dumb" terminal output, not
    // a proper interactive one
    mSession.setTermOut(new NullOutputStream());

    mOS = new PipedOutputStream();
    try {//from w ww .j ava 2 s  .  c  om
        mSession.setTermIn(new PipedInputStream(mOS));
    } catch (IOException e) {
        throw new IllegalStateException("Failed to set terminal input stream to pipe", e);
    }

    mEmulatorView.attachSession(mSession);

    // Start and bind to the service
    Intent intent = new Intent(getActivity(), SwitcherService.class);
    getActivity().bindService(intent, this, Context.BIND_AUTO_CREATE);
    getActivity().startService(intent);
}

From source file:com.SmartDial.BackgroundMode.java

/**
 * Bind the activity to a background service and put them into foreground
 * state./*from   w  ww .j  a  v a  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:com.librelio.activity.BillingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wait_bar);/*from ww  w. j a  v a  2s.  c o m*/

    setResult(RESULT_CANCELED);

    if (!isNetworkConnected()) {
        showAlertDialog(CONNECTION_ALERT);
    } else {
        Intent iapIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        iapIntent.setPackage("com.android.vending");
        getContext().bindService(iapIntent, mServiceConn, Context.BIND_AUTO_CREATE);
        if (getIntent().getExtras() != null) {
            fileName = getIntent().getExtras().getString(FILE_NAME_KEY);
            title = getIntent().getExtras().getString(TITLE_KEY);
            subtitle = getIntent().getExtras().getString(SUBTITLE_KEY);
            // Using Locale.US to avoid different results in different
            // locales
            productId = FilenameUtils.getName(fileName).toLowerCase(Locale.US);
            productId = productId.substring(0, productId.indexOf("_.pdf"));
        }
    }
}

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

/**
 * bind an activity to to an already running server.
 */// w w w .j  av a2s .  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.SecUpwN.AIMSICD.fragments.MapFragment.java

@Override
public void onResume() {
    super.onResume();
    setUpMapIfNeeded();/*from w  ww  .j  a  va  2s .c  om*/

    prefs = getActivity().getSharedPreferences(AimsicdService.SHARED_PREFERENCES_BASENAME, 0);
    prefs.registerOnSharedPreferenceChangeListener(this);

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMessageReceiver,
            new IntentFilter(updateOpenCellIDMarkers));

    if (!mBound) {
        // Bind to LocalService
        Intent intent = new Intent(getActivity(), AimsicdService.class);
        getActivity().bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    }

    loadPreferences();
    loadEntries();

    if (mCompassOverlay != null) {
        mCompassOverlay.enableCompass();
    }

    if (mMyLocationOverlay != null) {
        mMyLocationOverlay.enableMyLocation();
    }
}

From source file:com.librelio.products.ui.ProductsBillingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wait_bar);//from   ww  w  . ja  v  a2 s.  c  o  m

    setResult(RESULT_CANCELED);

    if (!isNetworkConnected()) {
        showAlertDialog(CONNECTION_ALERT);
    } else {
        Intent iapIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        iapIntent.setPackage("com.android.vending");
        getContext().bindService(iapIntent, mServiceConn, Context.BIND_AUTO_CREATE);
        if (getIntent().getExtras() != null) {
            fileName = getIntent().getExtras().getString(FILE_NAME_KEY);
            title = getIntent().getExtras().getString(TITLE_KEY);
            subtitle = getIntent().getExtras().getString(SUBTITLE_KEY);
            // Using Locale.US to avoid different results in different
            // locales
            productId = FilenameUtils.getName(fileName).toLowerCase(Locale.US);
            productId = productId.substring(0, productId.indexOf("_.sqlite"));
        }
    }
}

From source file:me.trashout.fragment.base.BaseFragment.java

private void bindService() {
    if (serviceClassArray != null && serviceClassArray.size() > 0 && !mBound) {
        for (Class<?> serviceClass : serviceClassArray) {
            getActivity().bindService(new Intent(getActivity(), serviceClass), mConnection,
                    Context.BIND_AUTO_CREATE);
        }/*from ww w  . j  a v a2 s . co m*/
        mBound = true;
    }
}