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:chaitanya.im.searchforreddit.LauncherActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // get and set theme from shared preferences
    sharedPref = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    theme = sharedPref.getInt(getString(R.string.style_pref_key), 0);
    donate = sharedPref.getInt(getString(R.string.donate_check), 0);
    UtilMethods.onActivityCreateSetTheme(this, theme, SOURCE);

    mServiceConn = new ServiceConnection() {
        @Override//w  w  w.  j  av  a2s .  c  om
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
            Log.d(TAG, "Service Connected");
            getPrices();
        }
    };

    //ComponentName myService = startService(new Intent(this, LauncherActivity.class));
    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

    // IAP stuff
    skuList = new ArrayList<>();
    skuList.add("donate");
    skuList.add("donate2");
    skuList.add("donate3");
    querySkus = new Bundle();
    querySkus.putStringArrayList("ITEM_ID_LIST", skuList);

    setContentView(R.layout.activity_launcher);

    // Obtain the FirebaseAnalytics instance.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    fontAwesome = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf");
    dialog = new GenericAlertDialog();
    dialog.setFontAwesome(fontAwesome);
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    LinearLayout searchBox = (LinearLayout) findViewById(R.id.search_box);
    searchOptions = (LinearLayout) findViewById(R.id.search_options);
    launcherRefresh = (SwipeRefreshLayout) findViewById(R.id.launcher_refresh);
    searchEditText = (EditText) findViewById(R.id.search_edit_text);
    clearSearchBoxButton = (ImageButton) findViewById(R.id.clearSearchBox);
    //filterButton = (Button) findViewById(R.id.filter_button);
    sortButton = (Button) findViewById(R.id.sort_button);
    timeButton = (Button) findViewById(R.id.time_button);
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.launcher_coordinatorlayout);
    searchOptions.post(new Runnable() {
        @Override
        public void run() {
            searchOptionsCenter = searchOptions.getWidth() / 2;
            if (searchOptions.getVisibility() != View.VISIBLE) {
                UtilMethods.revealView(searchOptions, searchOptionsCenter, 0);
            }
        }
    });
    setSupportActionBar(toolbar);

    searchEditText.setOnKeyListener(onKeyListener);
    searchEditText.setOnTouchListener(searchEditTextTouchListener);

    sortButton.setOnLongClickListener(buttonLongClick);
    timeButton.setOnLongClickListener(buttonLongClick);
    //filterButton.setOnLongClickListener(buttonLongClick);

    rvResults = (RecyclerView) findViewById(R.id.result_view_launcher);
    ResultsAdapter adapter = new ResultsAdapter(resultList, this);
    rvResults.setAdapter(adapter);
    rvResults.setLayoutManager(new LinearLayoutManager(this));
    rvResults.addItemDecoration(new SimpleDividerItemDecoration(this, theme));

    //rvResults.setRecyclerListener(recyclerListener);
    urlSearch = new UrlSearch(BASE_URL, this, 1, adapter);

    // dp -> px : http://stackoverflow.com/a/9563438/1055475
    Resources resources = getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float px = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(px * 4);
        searchBox.setElevation(px * 3);
    } else {
        findViewById(R.id.shadow).setVisibility(View.VISIBLE);
        findViewById(R.id.shadow2).setVisibility(View.VISIBLE);
    }
    Log.d(TAG, "OnCreate");
    Log.d(TAG, "searchEditText - " + searchEditText.getText().toString());

    launcherRefresh.setOnRefreshListener(refreshListener);
    launcherRefresh.setColorSchemeResources(R.color.blue_tint, R.color.reddit_orange,
            R.color.material_light_black);

    UtilMethods.getLocation();

    Intent intent = getIntent();
    receiveIntent(intent);
}

From source file:fr.enseirb.odroidx.remote_client.MainActivity.java

@Override
protected void onStart() {
    super.onStart();
    bindService(new Intent(getApplicationContext(), CommunicationService.class), serviceConnection,
            Context.BIND_AUTO_CREATE);
}

From source file:com.soomla.store.billing.google.GoogleIabHelper.java

/**
 * See parent//from   ww  w  .jav  a  2s.c  om
 */
protected void startSetupInner() {
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            SoomlaUtils.LogDebug(TAG, "Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            SoomlaUtils.LogDebug(TAG, "Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = SoomlaApp.getAppContext().getPackageName();
            try {
                SoomlaUtils.LogDebug(TAG, "Checking for in-app billing 3 support.");

                // check for in-app billing v3 support
                int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != IabResult.BILLING_RESPONSE_RESULT_OK) {
                    setupFailed(new IabResult(response, "Error checking for billing v3 support."));
                    return;
                }
                SoomlaUtils.LogDebug(TAG, "In-app billing version 3 supported for " + packageName);

                setupSuccess();
            } catch (RemoteException e) {
                setupFailed(new IabResult(IabResult.IABHELPER_REMOTE_EXCEPTION,
                        "RemoteException while setting up in-app billing."));
                e.printStackTrace();
            }
        }
    };

    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    List<ResolveInfo> intentServices = SoomlaApp.getAppContext().getPackageManager()
            .queryIntentServices(serviceIntent, 0);
    if (intentServices != null && !intentServices.isEmpty()) {
        // service available to handle that Intent
        SoomlaApp.getAppContext().bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        setupFailed(new IabResult(IabResult.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                "Billing service unavailable on device."));
    }
}

From source file:com.soomla.store.billing.tapclash.TapClashIabHelper.java

/**
 * See parent/* w ww. j  av  a 2 s. com*/
 */
protected void startSetupInner() {
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            SoomlaUtils.LogDebug(TAG, "Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            SoomlaUtils.LogDebug(TAG, "Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = SoomlaApp.getAppContext().getPackageName();
            try {
                SoomlaUtils.LogDebug(TAG, "Checking for in-app billing 3 support.");

                // check for in-app billing v3 support
                int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != IabResult.BILLING_RESPONSE_RESULT_OK) {
                    setupFailed(new IabResult(response, "Error checking for billing v3 support."));
                    return;
                }
                SoomlaUtils.LogDebug(TAG, "In-app billing version 3 supported for " + packageName);

                setupSuccess();
            } catch (RemoteException e) {
                setupFailed(new IabResult(IabResult.IABHELPER_REMOTE_EXCEPTION,
                        "RemoteException while setting up in-app billing."));
                e.printStackTrace();
            }
        }
    };

    Intent serviceIntent = new Intent("com.gametree.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.gametree.estore");
    List<ResolveInfo> intentServices = SoomlaApp.getAppContext().getPackageManager()
            .queryIntentServices(serviceIntent, 0);
    if (intentServices != null && !intentServices.isEmpty()) {
        // service available to handle that Intent
        SoomlaApp.getAppContext().bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        setupFailed(new IabResult(IabResult.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                "Billing service unavailable on device."));
    }
}

From source file:de.schildbach.wallet.ui.ChannelRequestActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.channel_request_view);

    wallet = getWalletApplication().getWallet();

    acceptButton = (Button) findViewById(R.id.send_coins_go);
    acceptButton.setText(R.string.button_allow);
    acceptButton.setEnabled(false);/*w  w  w .j  av  a2s. c o m*/
    acceptButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (validateAmounts(true)) {
                userSpecifiedMaxValue = currencyCalculatorLink.getAmount();
                if (service == null)
                    bindService(new Intent(ChannelRequestActivity.this, ChannelService.class), connection,
                            Context.BIND_AUTO_CREATE);
                else
                    allowAndFinish();
                disconnectAndFinish(Activity.RESULT_OK);
            }
        }
    });

    Button rejectButton = (Button) findViewById(R.id.send_coins_cancel);
    rejectButton.setText(R.string.button_reject);
    rejectButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismissPopup();
            disconnectAndFinish(Activity.RESULT_CANCELED);
        }
    });

    popupAvailableView = getLayoutInflater().inflate(R.layout.send_coins_popup_available, null);
    popupMessageView = (TextView) getLayoutInflater().inflate(R.layout.send_coins_popup_message, null);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    btcAmountView = (CurrencyAmountView) findViewById(R.id.channel_value_view_btc);
    btcAmountView.setCurrencySymbol(Constants.CURRENCY_CODE_BITCOIN);
    btcAmountView.setHintPrecision(Integer.parseInt(
            prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION)));

    CurrencyAmountView localAmountView = (CurrencyAmountView) findViewById(R.id.channel_value_view_local);
    localAmountView.setHintPrecision(Constants.LOCAL_PRECISION);

    currencyCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView);
    currencyCalculatorLink.setListener(amountsListener);
    currencyCalculatorLink.setEnabled(true);

    loaderManager = getSupportLoaderManager();

    handleIntent(getIntent());
}

From source file:com.sdrtouch.rtlsdr.DeviceOpenActivity.java

/** 
 * Starts the tcp binary/*from   w w w.  j a  v a  2s.c om*/
 */
public void startServer(final SdrDevice sdrDevice) {
    try {

        //start the service
        this.sdrDevice = sdrDevice;
        sdrDevice.addOnStatusListener(onDeviceStatusListener);
        Intent serviceIntent = new Intent(this, BinaryRunnerService.class);
        bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
    } catch (Exception e) {
        finishWithError(e);
    }
}

From source file:jp.app_mart.billing.AppmartHelper.java

/**
 * appmart???//from   w  ww. jav a  2 s . c  o m
 * @param listener Activity?callback
 */
public void startSetup(final OnAppmartSetupFinishedListener listener) {

    if (mSetupDone)
        throw new IllegalStateException(mContext.getString(R.string.already_connected));

    mServiceConn = new ServiceConnection() {

        //?
        public void onServiceConnected(ComponentName name, IBinder boundService) {
            mService = AppmartInBillingInterface.Stub.asInterface((IBinder) boundService);
            mSetupDone = true;
            if (listener != null) {
                listener.onAppmartSetupFinished(new AppmartResult(BILLING_RESPONSE_RESULT_OK,
                        mContext.getString(R.string.is_now_connected)));
            }

            //????receiver
            IntentFilter filter = new IntentFilter("appmart_broadcast_return_service_payment");
            if (mReceiver == null)
                mReceiver = new AppmartReceiver();
            mContext.registerReceiver(mReceiver, filter);
        }

        //?
        public void onServiceDisconnected(ComponentName name) {
            logDebug(mContext.getString(R.string.is_now_deconnected));
            mService = null;
        }
    };

    Intent serviceIntent = new Intent();
    serviceIntent.setClassName(BILLING_APPMART_PACKAGE_NAME, BILLING_APPMART_SERVICE_NAME);

    //?appmart????????
    if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {

        mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

    } else {

        if (listener != null) {
            listener.onAppmartSetupFinished(new AppmartResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                    mContext.getString(R.string.appmart_not_installed)));
        }
    }
}

From source file:com.wifi.brainbreaker.mydemo.spydroid.ui.SpydroidActivity.java

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

    // Lock screen
    mWakeLock.acquire();// ww w  .j  a v  a 2s.  c o m

    // Did the user disabled the notification ?
    if (mApplication.notificationEnabled) {
        Intent notificationIntent = new Intent(this, SpydroidActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        Notification notification = builder.setContentIntent(pendingIntent).setWhen(System.currentTimeMillis())
                .setTicker(getText(R.string.notification_title)).setSmallIcon(R.drawable.icon)
                .setContentTitle(getText(R.string.notification_title))
                .setContentText(getText(R.string.notification_content)).build();
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification);
    } else {
        removeNotification();
    }

    bindService(new Intent(this, CustomHttpServer.class), mHttpServiceConnection, Context.BIND_AUTO_CREATE);
    bindService(new Intent(this, CustomRtspServer.class), mRtspServiceConnection, Context.BIND_AUTO_CREATE);

}

From source file:edu.asu.cse535.assignment3.MainActivity.java

public void onStartRecordingEating(View v) {
    Log.w(this.getClass().getSimpleName(), "Button is clicked");
    intent = new Intent(MainActivity.this.getBaseContext(), AccIntentService.class);
    intent.putExtra("activity", Constants.ACTIVITY_EATING);
    startService(intent);/*  w w  w  .j  ava  2s . c  om*/
    serve = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            accIntentService = ((AccIntentService.LocalBinder) service).getInstance();
            accIntentService.setHandler(handler);
            Log.w(this.getClass().getSimpleName(), "Activity is connected to service");
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

    bindService(intent, serve, Context.BIND_AUTO_CREATE);
}

From source file:net.networksaremadeofstring.rhybudd.AddDeviceFragment.java

void doBindService() {
    try {/*from w ww.  java  2s  .  c  o m*/
        getActivity().bindService(new Intent(getActivity(), ZenossPoller.class), mConnection,
                Context.BIND_AUTO_CREATE);
        mBound = true;
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("AddDeviceFragment", "doBindService", e);
    }
}