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:net.kseek.camtest.ui.CamtestActivity.java

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

    // Lock screen
    mWakeLock.acquire();/*from  ww w.j  a va2 s. c o m*/

    // Did the user disabled the notification ?
    if (mApplication.notificationEnabled) {
        Intent notificationIntent = new Intent(this, CamtestActivity.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:eu.focusnet.app.ui.activity.ProjectsListingActivity.java

/**
 * Create the activity./*from w w w . ja  v a  2s .c  o m*/
 * - the parent {@code onCreate()} method will setup and render the UI
 * - we bind to {@link CronService}
 *
 * @param savedInstanceState Inherited.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    // this method will take care of building the UI and rendering, using later
    // overriden methods
    super.onCreate(savedInstanceState);

    // bind cron service
    Intent intent = new Intent(this, CronService.class);
    bindService(intent, this.cronServiceConnection, Context.BIND_AUTO_CREATE);

}

From source file:fr.s13d.photobackup.preferences.PBPreferenceFragment.java

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

    initPreferences();//from ww w  . j  a  va 2  s. c  o m
    preferences.registerOnSharedPreferenceChangeListener(this);
    PBApplication.getMediaStore().addInterface(this);

    if (isPhotoBackupServiceRunning()) {
        Intent intent = new Intent(this.getActivity(), PBService.class);
        getActivity().bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
        isBoundToService = true;
    }

    updatePreferences();
    try {
        fillBuckets();
    } catch (SecurityException e) {
        Log.d(LOG_TAG, e);
    }

}

From source file:cx.ring.client.AccountEditionActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!mBound) {
        Intent intent = new Intent(this, LocalService.class);
        bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    }//w  w  w.ja v a2 s  .  c om
}

From source file:es.rgmf.libresportgps.MainActivity.java

/**
 * This method is called each time the activity is executed. For example
 * when you change from other application to it.
 *//*from   w  w  w  .  ja  va 2  s.c  o m*/
@Override
protected void onResume() {
    super.onResume();

    // Get preferences and populate data in Session.
    populateSessionWithPrefs();

    // Starts GPS Service and bind it to this Activity.
    Session.setBoundToService(true);
    startService(serviceIntent);
    bindService(serviceIntent, gpsServiceConnection, Context.BIND_AUTO_CREATE);
}

From source file:com.google.android.gms.location.sample.locationupdatesforegroundservice.MainActivity.java

@Override
protected void onStart() {
    super.onStart();
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);

    mRequestLocationUpdatesButton = (Button) findViewById(R.id.request_location_updates_button);
    mRemoveLocationUpdatesButton = (Button) findViewById(R.id.remove_location_updates_button);

    mRequestLocationUpdatesButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w w  w  .j av a  2 s.c o m*/
        public void onClick(View view) {
            if (!checkPermissions()) {
                requestPermissions();
            } else {
                mService.requestLocationUpdates();
            }
        }
    });

    mRemoveLocationUpdatesButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mService.removeLocationUpdates();
        }
    });

    // Restore the state of the buttons when the activity (re)launches.
    setButtonsState(Utils.requestingLocationUpdates(this));

    // Bind to the service. If the service is in foreground mode, this signals to the service
    // that since this activity is in the foreground, the service can exit foreground mode.
    bindService(new Intent(this, LocationUpdatesService.class), mServiceConnection, Context.BIND_AUTO_CREATE);
}

From source file:com.jetheis.android.makeitrain.billing.googleplay.GooglePlayBillingWrapper.java

private GooglePlayBillingWrapper(Context context, OnGooglePlayBillingReadyListener onReadyListener,
        OnGooglePlayVipModePurchaseFoundListener onPurchaseListener) {
    mContext = context;/*from  ww  w  .  java 2  s. c o  m*/
    mOnReadyListener = onReadyListener;
    mOnPurchaseListnener = onPurchaseListener;

    context.startService(new Intent(context, GooglePlayBillingService.class));

    mConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mBoundService = ((GooglePlayBillingService.GooglePlayBillingBinder) service).getService();
            mBoundService.checkIsBillingSupported(new OnGooglePlayBillingSupportResultListener() {

                @Override
                public void onGooglePlayBillingSupportResultFound(boolean billingSupported) {
                    if (billingSupported) {
                        Log.i(Constants.TAG, "Google Play billing ready");
                        if (mOnReadyListener != null) {
                            mOnReadyListener.onGooglePlayBillingReady();
                        }
                    } else {
                        Log.i(Constants.TAG, "Google Play billing is not supported");
                        if (mOnReadyListener != null) {
                            mOnReadyListener.onGooglePlayBillingNotSupported();
                        }
                    }
                }

            });

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            mBoundService = null;
        }

    };

    mContext.bindService(new Intent(context, GooglePlayBillingService.class), mConnection,
            Context.BIND_AUTO_CREATE);
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.fragments.SensorConfigFragment.java

private void startSensorModule() {
    //      progressDialog = new ProgressDialog(getActivity());
    //      progressDialog.setTitle("");
    //      progressDialog.setMessage("Loading...");
    //      progressDialog.setCancelable(false);
    //      progressDialog.setIndeterminate(true);
    //      progressDialog.show();

    /* Preferences */
    preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());

    // StartProducer message handler
    mMessageHandlerIntent = new Intent(getActivity().getApplicationContext(), MessageHandler.class);
    getActivity().startService(mMessageHandlerIntent);

    registerForContextMenu(getListView());

    mSensorModuleManagerIntent = new Intent(getActivity(), SensorModuleManager.class);
    getActivity().getApplicationContext().bindService(mSensorModuleManagerIntent,
            mSensorModuleManagerConnection, Context.BIND_AUTO_CREATE);
    getActivity().startService(mSensorModuleManagerIntent);
}

From source file:com.develop.autorus.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Fabric.with(this, new Crashlytics());
    super.onCreate(savedInstanceState);
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

    AnalyticsApplication application = (AnalyticsApplication) getApplication();
    mTracker = application.getDefaultTracker();
    mTracker.setScreenName("Main activity");
    mTracker.send(new HitBuilders.ScreenViewBuilder().build());

    if (pref.getBoolean("notificationIsActive", true)) {
        Intent checkIntent = new Intent(getApplicationContext(), MonitoringWork.class);
        Boolean alrarmIsActive = false;
        if (PendingIntent.getService(getApplicationContext(), 0, checkIntent,
                PendingIntent.FLAG_NO_CREATE) != null)
            alrarmIsActive = true;/*from ww  w. j  a v  a 2s. c om*/
        am = (AlarmManager) getSystemService(ALARM_SERVICE);

        if (!alrarmIsActive) {
            Intent serviceIntent = new Intent(getApplicationContext(), MonitoringWork.class);
            PendingIntent pIntent = PendingIntent.getService(getApplicationContext(), 0, serviceIntent, 0);

            int period = pref.getInt("numberOfActiveMonitors", 0) * 180000;

            if (period != 0)
                am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period,
                        period, pIntent);
        }
    }

    /*ForEasyDelete
            
    //Danger! Auchtung! ?, !!!
    String base64EncodedPublicKey =
        "<your license key here>";//?   . !!! ? ,    
    // github ?  .         ?!!!
            
    mHelper = new IabHelper(this, base64EncodedPublicKey);
            
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
    public void onIabSetupFinished(IabResult result) {
        if (!result.isSuccess()) {
            Log.d(TAG, "In-app Billing setup failed: " +
                    result);
        } else {
            Log.d(TAG, "In-app Billing is set up OK");
        }
    }
    });
    */

    //Service inapp
    Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    intent.setPackage("com.android.vending");
    blnBind = bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);

    String themeName = pref.getString("theme", "1");

    if (themeName.equals("1")) {
        setTheme(R.style.AppTheme);
        if (android.os.Build.VERSION.SDK_INT >= 21) {
            Window statusBar = getWindow();
            statusBar.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            statusBar.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            statusBar.setStatusBarColor(getResources().getColor(R.color.myPrimaryDarkColor));
        }
    } else if (themeName.equals("2")) {
        setTheme(R.style.AppTheme2);
        if (android.os.Build.VERSION.SDK_INT >= 21) {
            Window statusBar = getWindow();
            statusBar.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            statusBar.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            statusBar.setStatusBarColor(getResources().getColor(R.color.myPrimaryDarkColor2));
        }
    }
    ThemeManager.init(this, 2, 0, null);

    if (isFirstLaunch) {
        SQLiteDatabase db = new DbHelper(this).getWritableDatabase();
        Cursor cursorMonitors = db.query("monitors", null, null, null, null, null, null);
        Boolean monitorsExist = cursorMonitors != null && cursorMonitors.getCount() > 0;
        db.close();

        if (getSupportFragmentManager().findFragmentByTag("MAIN") == null) {
            FragmentTransaction fTrans = getSupportFragmentManager().beginTransaction();
            if (monitorsExist)
                mainFragment = SearchAndMonitorsFragment.newInstance(0);
            else
                mainFragment = SearchAndMonitorsFragment.newInstance(1);
            fTrans.add(R.id.container, mainFragment, "MAIN").commit();
        } else {
            mainFragment = (SearchAndMonitorsFragment) getSupportFragmentManager().findFragmentByTag("MAIN");
            if (getSupportFragmentManager().findFragmentByTag("Second") != null) {
                FragmentTransaction fTrans = getSupportFragmentManager().beginTransaction();
                fTrans.remove(getSupportFragmentManager().findFragmentByTag("Second")).commit();
            }
            pref.edit().remove("NumberOfCallingFragment");
        }
    }

    backToast = Toast.makeText(this, "?   ? ", Toast.LENGTH_SHORT);
    setContentView(R.layout.main_activity);
    mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    mSnackBar = (SnackBar) findViewById(R.id.main_sn);
    setSupportActionBar(mToolbar);

    addMonitorButton = (Button) findViewById(R.id.toolbar_add_monitor_button);

    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.fragment_drawer);
    mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);

    Thread threadAvito = new Thread(new Runnable() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        public void run() {
            Document doc;
            SharedPreferences sPref;
            try {
                String packageName = getApplicationContext().getPackageName();
                doc = Jsoup.connect("https://play.google.com/store/apps/details?id=" + packageName).userAgent(
                        "Mozilla/5.0 (Windows; U; WindowsNT 5.1; ru-RU; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                        .timeout(12000).get();
                //"")

                PackageManager packageManager;
                PackageInfo packageInfo;
                packageManager = getPackageManager();

                packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
                Element mainElems = doc.select(
                        "#body-content > div > div > div.main-content > div.details-wrapper.apps-secondary-color > div > div.details-section-contents > div:nth-child(4) > div.content")
                        .first();

                if (!packageInfo.versionName.equals(mainElems.text())) {
                    sPref = getPreferences(MODE_PRIVATE);
                    SharedPreferences.Editor ed = sPref.edit();
                    ed.putBoolean(SAVED_TEXT_WITH_VERSION, false);
                    ed.commit();
                } else {
                    sPref = getPreferences(MODE_PRIVATE);
                    SharedPreferences.Editor ed = sPref.edit();
                    ed.putBoolean(SAVED_TEXT_WITH_VERSION, true);
                    ed.commit();

                }
                //SharedPreferences sPrefRemind;
                //sPrefRemind = getPreferences(MODE_PRIVATE);
                //sPrefRemind.edit().putBoolean(DO_NOT_REMIND, false).commit();
            } catch (HttpStatusException e) {
                return;
            } catch (IOException e) {
                return;
            } catch (PackageManager.NameNotFoundException e) {

                e.printStackTrace();
            }
        }
    });

    SharedPreferences sPrefVersion;
    sPrefVersion = getPreferences(MODE_PRIVATE);
    Boolean isNewVersion;
    isNewVersion = sPrefVersion.getBoolean(SAVED_TEXT_WITH_VERSION, true);

    threadAvito.start();
    boolean remind = true;
    if (!isNewVersion) {
        Log.d("affa", "isNewVersion= " + isNewVersion);
        SharedPreferences sPref12;
        sPref12 = getPreferences(MODE_PRIVATE);
        String isNewVersion12;

        PackageManager packageManager;
        PackageInfo packageInfo;
        packageManager = getPackageManager();

        try {
            packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
            isNewVersion12 = sPref12.getString("OldVersionName", packageInfo.versionName);

            if (!isNewVersion12.equals(packageInfo.versionName)) {
                SharedPreferences sPref;
                sPref = getPreferences(MODE_PRIVATE);
                SharedPreferences.Editor ed = sPref.edit();
                ed.putBoolean(SAVED_TEXT_WITH_VERSION, false);
                ed.commit();

                SharedPreferences sPrefRemind;
                sPrefRemind = getPreferences(MODE_PRIVATE);
                sPrefRemind.edit().putBoolean(DO_NOT_REMIND, false).commit();
            } else
                remind = false;

            SharedPreferences sPrefRemind;
            sPrefRemind = getPreferences(MODE_PRIVATE);
            sPrefRemind.edit().putString("OldVersionName", packageInfo.versionName).commit();
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        SharedPreferences sPrefRemind;
        sPrefRemind = getPreferences(MODE_PRIVATE);
        Boolean dontRemind;
        dontRemind = sPrefRemind.getBoolean(DO_NOT_REMIND, false);
        Log.d("affa", "dontRemind= " + dontRemind.toString());
        Log.d("affa", "remind= " + remind);
        Log.d("affa", "44444444444444444444444= ");
        if ((!dontRemind) && (!remind)) {
            Log.d("affa", "5555555555555555555555555= ");
            SimpleDialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    super.onPositiveActionClicked(fragment);
                    String packageName = getApplicationContext().getPackageName();
                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/details?id=" + packageName));
                    startActivity(intent);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                }

                @Override
                public void onNeutralActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                    SharedPreferences sPrefRemind;
                    sPrefRemind = getPreferences(MODE_PRIVATE);
                    sPrefRemind.edit().putBoolean(DO_NOT_REMIND, true).commit();
                }
            };

            builder.message(
                    "  ??   ? ? ?")
                    .title(" !").positiveAction("")
                    .negativeAction("").neutralAction("? ");
            DialogFragment fragment = DialogFragment.newInstance(builder);
            fragment.show(getSupportFragmentManager(), null);
        }
    }
}

From source file:com.pertamina.tbbm.rewulu.ecodriving.MainActivity.java

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    Loggers.w("", "super.onResume()");
    if (layang == null)
        bindService(new Intent().setClass(getApplicationContext(), Layang.class), serviceConnection,
                Context.BIND_AUTO_CREATE);
    if (layang != null && user == null) {
        user = UserDataSP.get(getApplicationContext());
        if (user != null)
            layang.session(user);/*from   w w  w  .  j  av  a  2  s  .c  o  m*/
    }
    onPause = false;
}