List of usage examples for android.content ServiceConnection ServiceConnection
ServiceConnection
From source file:org.phillyopen.mytracks.cyclephilly.MainInput.java
/** Called when the activity is first created. */ @Override/*from w w w . java 2 s . c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Firebase.setAndroidContext(this); final Firebase ref = new Firebase("https://cyclephilly.firebaseio.com"); final Firebase phlref = new Firebase("https://phl.firebaseio.com"); // Let's handle some launcher lifecycle issues: // If we're recording or saving right now, jump to the existing activity. // (This handles user who hit BACK button while recording) setContentView(R.layout.main); weatherFont = Typeface.createFromAsset(getAssets(), "cyclephilly.ttf"); weatherText = (TextView) findViewById(R.id.weatherView); weatherText.setTypeface(weatherFont); weatherText.setText(R.string.cloudy); Intent rService = new Intent(this, RecordingService.class); ServiceConnection sc = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { } public void onServiceConnected(ComponentName name, IBinder service) { IRecordService rs = (IRecordService) service; int state = rs.getState(); if (state > RecordingService.STATE_IDLE) { if (state == RecordingService.STATE_FULL) { startActivity(new Intent(MainInput.this, SaveTrip.class)); } else { // RECORDING OR PAUSED: startActivity(new Intent(MainInput.this, RecordingActivity.class)); } MainInput.this.finish(); } else { // Idle. First run? Switch to user prefs screen if there are no prefs stored yet SharedPreferences settings = getSharedPreferences("PREFS", 0); String anon = settings.getString("" + PREF_ANONID, "NADA"); if (settings.getAll().isEmpty()) { showWelcomeDialog(); } else if (anon == "NADA") { showWelcomeDialog(); } // Not first run - set up the list view of saved trips ListView listSavedTrips = (ListView) findViewById(R.id.ListSavedTrips); populateList(listSavedTrips); } MainInput.this.unbindService(this); // race? this says we no longer care } }; // This needs to block until the onServiceConnected (above) completes. // Thus, we can check the recording status before continuing on. bindService(rService, sc, Context.BIND_AUTO_CREATE); // And set up the record button final Button startButton = (Button) findViewById(R.id.ButtonStart); final Intent i = new Intent(this, RecordingActivity.class); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.US); SharedPreferences settings = getSharedPreferences("PREFS", 0); final String anon = settings.getString("" + PREF_ANONID, "NADA"); Firebase weatherRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia"); Firebase tempRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia/currently"); tempRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Object val = dataSnapshot.getValue(); String cardinal = null; TextView tempState = (TextView) findViewById(R.id.temperatureView); // TextView liveTemp = (TextView) findViewById(R.id.warning); String apparentTemp = ((Map) val).get("apparentTemperature").toString(); String windSpeed = ((Map) val).get("windSpeed").toString(); Double windValue = (Double) ((Map) val).get("windSpeed"); Long windBearing = (Long) ((Map) val).get("windBearing"); // liveTemp.setText(" "+apparentTemp.toString()+DEGREE); WindDirection[] windDirections = WindDirection.values(); for (int i = 0; i < windDirections.length; i++) { if (windDirections[i].startDegree < windBearing && windDirections[i].endDegree > windBearing) { //Get Cardinal direction cardinal = windDirections[i].cardinal; } } if (windValue > 4) { tempState.setTextColor(0xFFDC143C); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph. Ride with caution."); } else { tempState.setTextColor(0xFFFFFFFF); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph."); } } @Override public void onCancelled(FirebaseError firebaseError) { } }); connectedListener = ref.getRoot().child(".info/connected").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { boolean connected = (Boolean) dataSnapshot.getValue(); if (connected) { System.out.println("connected " + dataSnapshot.toString()); Firebase cycleRef = new Firebase(FIREBASE_REF + "/" + anon + "/connections"); // cycleRef.setValue(Boolean.TRUE); // cycleRef.onDisconnect().removeValue(); } else { System.out.println("disconnected"); } } @Override public void onCancelled(FirebaseError error) { // No-op } }); weatherRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Object value = snapshot.getValue(); Object hourly = ((Map) value).get("currently"); String alert = ((Map) hourly).get("summary").toString(); // TextView weatherAlert = (TextView) findViewById(R.id.weatherAlert); // weatherAlert.setText(alert); } @Override public void onCancelled(FirebaseError firebaseError) { } }); // Acquire a reference to the system Location Manager // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. mySpot = new LatLng(location.getLatitude(), location.getLongitude()); makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; nearbyStations = (RecyclerView) findViewById(R.id.nearbyStationList); nearbyStations.setLayoutManager(new LinearLayoutManager(getApplicationContext())); //Listener for Indego Changes indegoRef = new Firebase("https://phl.firebaseio.com/indego/kiosks"); indegoRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { //Updates! Add them to indego data list indegoDataList = dataSnapshot; } @Override public void onCancelled(FirebaseError firebaseError) { } }); // Register the listener with the Location Manager to receive location updates indegoGeofireRef = new Firebase("https://phl.firebaseio.com/indego/_geofire"); GeoFire geoFire = new GeoFire(indegoGeofireRef); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); mySpot = myCurrentLocation(); indegoList = new ArrayList<IndegoStation>(); System.out.println("lo: " + mySpot.toString()); GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(mySpot.longitude, mySpot.latitude), 0.5); geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { @Override public void onKeyEntered(String key, GeoLocation location) { System.out.println(String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude)); //Create Indego Station object. To-do: check if object exists IndegoStation station = new IndegoStation(); station.kioskId = key; station.location = location; if (indegoDataList != null) { //get latest info from list station.name = (String) indegoDataList.child(key).child("properties").child("name").getValue(); } System.out.println(station.name); indegoList.add(station); //To-do: Add indego station info to RideIndegoAdapter } @Override public void onKeyExited(String key) { } @Override public void onKeyMoved(String key, GeoLocation location) { } @Override public void onGeoQueryReady() { System.out.println("GEO READY :" + indegoList.toString()); indegoAdapter = new RideIndegoAdapter(getApplicationContext(), indegoList); nearbyStations.setAdapter(indegoAdapter); } @Override public void onGeoQueryError(FirebaseError error) { System.out.println("GEO error"); } }); startButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Before we go to record, check GPS status final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); } else { startActivity(i); MainInput.this.finish(); } } }); toolbar = (Toolbar) findViewById(R.id.dashboard_bar); toolbar.setTitle("Cycle Philly"); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); }
From source file:com.rareventure.gps2.reviewer.wizard.WelcomePage.java
public void moveTrialDataToPremiumDir(final WTask wTask) { isMoveTrialRunning = true;// w w w. j av a 2s . c o m Intent i = new Intent(ITrialService.class.getName()).setPackage(GTG.TRIAL_APPLICATION_PACKAGE); boolean boundSuccessfully = true; ServiceConnection serviceConnection = null; try { if (!bindService(i, serviceConnection = new ServiceConnection() { private boolean serviceAlreadyConnected; @Override public void onServiceDisconnected(ComponentName name) { } @Override public void onServiceConnected(ComponentName name, IBinder service) { try { Log.d(GTG.TAG, "welcome page: service connected"); if (serviceAlreadyConnected) return; serviceAlreadyConnected = true; ITrialService mService = ITrialService.Stub.asInterface(service); Map<String, Object> prefsMap = mService.giveMePreferences(); String trialDirString = mService.getExtFileDir(); Log.d(GTG.TAG, "welcome page: got ext file dir"); // we don't worry about synchronization here, because we only do this during // initial setup GTG.prefSet.loadAndroidPreferencesFromMap(WelcomePage.this, prefsMap); GTG.prefSet.saveSharedPrefs(WelcomePage.this); mService.notifyReplaced(); //shutdown the trial app commpletely before we start moving the files try { mService.shutdown(); } catch (Exception e) { //an exception is thrown because it kills the process Log.i(GTG.TAG, "Trial shutdown"); } File trialDir = new File(trialDirString); File myFileDir = GTG.getExternalStorageDirectory(); for (File subFile : trialDir.listFiles()) { //we don't freak out on failure here. Hopefully gps.db3 will be moved at least. //if not, a new db will be created with no points if (!subFile.renameTo(new File(myFileDir + "/" + subFile.getName()))) Log.e(GTG.TAG, "Couldn't move file " + subFile + " to " + myFileDir); } } catch (Exception e) { Log.e(GTG.TAG, "Error trying to move trial data", e); } wTask.notifyFinish(); //restart startReviewer now that we may have trial data runOnUiThread(new Runnable() { public void run() { startWelcomePage(true); } }); unbindService(this); //we restart the trial app, so that it will shut off the notification frog. Since we kill it before we //moved the files away, it didn't have time to shut it off itself. Intent i = new Intent(GpsTrailerReceiver.class.getName()) .setPackage(GTG.TRIAL_APPLICATION_PACKAGE); Log.d(GTG.TAG, "Sending broadcast to " + i + ", name " + GpsTrailerReceiver.class.getName()); sendBroadcast(i); } }, Context.BIND_AUTO_CREATE)) boundSuccessfully = false; } catch (Exception e) { Log.e(GTG.TAG, "Exception trying to bind service", e); boundSuccessfully = false; } finally { } if (!boundSuccessfully) { Log.d(GTG.TAG, "welcome page: could not bind service"); wTask.notifyFinish(); isMoveTrialRunning = false; startWelcomePage(true); //even if we don't bind the service, we still have to unbind or android complains about a leaked service connection if (serviceConnection != null) unbindService(serviceConnection); } }
From source file:org.opensmc.mytracks.cyclesmc.MainInput.java
/** Called when the activity is first created. */ @Override//from w w w .j a v a 2 s .co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Firebase.setAndroidContext(this); final Firebase ref = new Firebase("https://org.opensmc.mytracks.cyclesmc.firebaseio.com"); final Firebase phlref = new Firebase("https://phl.firebaseio.com"); // Let's handle some launcher lifecycle issues: // If we're recording or saving right now, jump to the existing activity. // (This handles user who hit BACK button while recording) setContentView(R.layout.main); weatherFont = Typeface.createFromAsset(getAssets(), "cyclesmc.ttf"); weatherText = (TextView) findViewById(R.id.weatherView); weatherText.setTypeface(weatherFont); weatherText.setText(R.string.cloudy); Intent rService = new Intent(this, RecordingService.class); ServiceConnection sc = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { } public void onServiceConnected(ComponentName name, IBinder service) { IRecordService rs = (IRecordService) service; int state = rs.getState(); if (state > RecordingService.STATE_IDLE) { if (state == RecordingService.STATE_FULL) { startActivity(new Intent(MainInput.this, SaveTrip.class)); } else { // RECORDING OR PAUSED: startActivity(new Intent(MainInput.this, RecordingActivity.class)); } MainInput.this.finish(); } else { // Idle. First run? Switch to user prefs screen if there are no prefs stored yet SharedPreferences settings = getSharedPreferences("PREFS", 0); String anon = settings.getString("" + PREF_ANONID, "NADA"); if (settings.getAll().isEmpty()) { showWelcomeDialog(); } else if (anon == "NADA") { showWelcomeDialog(); } // Not first run - set up the list view of saved trips ListView listSavedTrips = (ListView) findViewById(R.id.ListSavedTrips); populateList(listSavedTrips); } MainInput.this.unbindService(this); // race? this says we no longer care } }; // This needs to block until the onServiceConnected (above) completes. // Thus, we can check the recording status before continuing on. bindService(rService, sc, Context.BIND_AUTO_CREATE); // And set up the record button final Button startButton = (Button) findViewById(R.id.ButtonStart); final Intent i = new Intent(this, RecordingActivity.class); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.US); SharedPreferences settings = getSharedPreferences("PREFS", 0); final String anon = settings.getString("" + PREF_ANONID, "NADA"); Firebase weatherRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia"); Firebase tempRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia/currently"); tempRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Object val = dataSnapshot.getValue(); String cardinal = null; TextView tempState = (TextView) findViewById(R.id.temperatureView); // TextView liveTemp = (TextView) findViewById(R.id.warning); String apparentTemp = ((Map) val).get("apparentTemperature").toString(); String windSpeed = ((Map) val).get("windSpeed").toString(); Double windValue = (Double) ((Map) val).get("windSpeed"); Long windBearing = (Long) ((Map) val).get("windBearing"); // liveTemp.setText(" "+apparentTemp.toString()+DEGREE); WindDirection[] windDirections = WindDirection.values(); for (int i = 0; i < windDirections.length; i++) { if (windDirections[i].startDegree < windBearing && windDirections[i].endDegree > windBearing) { //Get Cardinal direction cardinal = windDirections[i].cardinal; } } if (windValue > 4) { tempState.setTextColor(0xFFDC143C); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph. Ride with caution."); } else { tempState.setTextColor(0xFFFFFFFF); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph."); } } @Override public void onCancelled(FirebaseError firebaseError) { } }); connectedListener = ref.getRoot().child(".info/connected").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { boolean connected = (Boolean) dataSnapshot.getValue(); if (connected) { System.out.println("connected " + dataSnapshot.toString()); // Firebase cycleRef = new Firebase(FIREBASE_REF+"/"+anon+"/connections"); // cycleRef.setValue(Boolean.TRUE); // cycleRef.onDisconnect().removeValue(); } else { System.out.println("disconnected"); } } @Override public void onCancelled(FirebaseError error) { // No-op } }); weatherRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Object value = snapshot.getValue(); Object hourly = ((Map) value).get("currently"); String alert = ((Map) hourly).get("summary").toString(); // TextView weatherAlert = (TextView) findViewById(R.id.weatherAlert); // weatherAlert.setText(alert); } @Override public void onCancelled(FirebaseError firebaseError) { } }); // Acquire a reference to the system Location Manager // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. mySpot = new LatLng(location.getLatitude(), location.getLongitude()); makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; //nearbyStations = (RecyclerView) findViewById(R.id.nearbyStationList); //nearbyStations.setLayoutManager(new LinearLayoutManager(getApplicationContext())); //Listener for Indego Changes /*indegoRef = new Firebase("https://phl.firebaseio.com/indego/kiosks"); indegoRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { //Updates! Add them to indego data list indegoDataList = dataSnapshot; } @Override public void onCancelled(FirebaseError firebaseError) { } });*/ // Register the listener with the Location Manager to receive location updates //indegoGeofireRef = new Firebase("https://phl.firebaseio.com/indego/_geofire"); //GeoFire geoFire = new GeoFire(indegoGeofireRef); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); mySpot = myCurrentLocation(); //indegoList = new ArrayList<IndegoStation>(); System.out.println("lo: " + mySpot.toString()); /* GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(mySpot.latitude,mySpot.longitude), 0.5); geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { @Override public void onKeyEntered(String key, GeoLocation location) { System.out.println(String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude)); //Create Indego Station object. To-do: check if object exists // IndegoStation station = new IndegoStation(); //station.kioskId = key; //station.location = location; /* if(indegoDataList != null){ //get latest info from list station.name = (String) indegoDataList.child(key).child("properties").child("name").getValue(); } System.out.println(station.name); //indegoList.add(station); //To-do: Add indego station info to RideIndegoAdapter } @Override public void onKeyExited(String key) { } @Override public void onKeyMoved(String key, GeoLocation location) { } @Override /* public void onGeoQueryReady() { //System.out.println("GEO READY :"+indegoList.toString()); // indegoAdapter = new RideIndegoAdapter(getApplicationContext(),indegoList); //nearbyStations.setAdapter(indegoAdapter); } @Override public void onGeoQueryError(FirebaseError error) { System.out.println("GEO error"); } });*/ startButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Before we go to record, check GPS status final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); } else { startActivity(i); MainInput.this.finish(); } } }); toolbar = (Toolbar) findViewById(R.id.dashboard_bar); toolbar.setTitle(getString(R.string.app_name)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); }
From source file:com.vanco.abplayer.BiliVideoViewActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)) return;/*from w ww .j a v a 2s. c o m*/ vPlayerServiceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { vPlayer = ((PlayerService.LocalBinder) service).getService(); mServiceConnected = true; if (mSurfaceCreated) vPlayerHandler.sendEmptyMessage(OPEN_FILE); } @Override public void onServiceDisconnected(ComponentName name) { vPlayer = null; mServiceConnected = false; } }; setVolumeControlStream(AudioManager.STREAM_MUSIC); parseIntent(getIntent()); loadView(R.layout.activity_video); manageReceivers(); findViews(); mCreated = true; startText = startText + "??\n??...??\n..."; startVideoInfo.setText(startText); new VideoViewInitTask().execute(); // AdPublic.addAd(BiliVideoViewActivity.this); // ? // timer.schedule(task, 0, AdPublic.time); }
From source file:org.onepf.oms.appstore.skubitUtils.SkubitIabHelper.java
/** * Starts the setup process. This will start up the setup process asynchronously. * You will be notified through the listener when the setup process is complete. * This method is safe to call from a UI thread. * * @param listener The listener to notify when the setup process is complete. *///from w ww . j a va2s . c o m public void startSetup(@Nullable final IabHelper.OnIabSetupFinishedListener listener) { // If already set up, can't do it again. if (mSetupDone) throw new IllegalStateException("IAB helper is already set up."); // Connection to IAB service Logger.d("Starting in-app billing setup."); mServiceConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { Logger.d("Billing service disconnected."); mService = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { Logger.d("Billing service connected."); mService = getServiceFromBinder(service); mComponentName = name; String packageName = mContext.getPackageName(); try { Logger.d("Checking for in-app billing 1 support."); // check for in-app billing v1 support int response = mService.isBillingSupported(1, packageName, ITEM_TYPE_INAPP); if (response != RESULT_OK) { if (listener != null) listener.onIabSetupFinished( new IabResult(response, "Error checking for billing v1 support.")); // if in-app purchases aren't supported, neither are subscriptions. mSubscriptionsSupported = false; return; } Logger.d("In-app billing version 1 supported for ", packageName); // check for v3 subscriptions support response = mService.isBillingSupported(1, packageName, ITEM_TYPE_SUBS); if (response == RESULT_OK) { Logger.d("Subscriptions AVAILABLE."); mSubscriptionsSupported = true; } else { Logger.d("Subscriptions NOT AVAILABLE. Response: ", response); } mSetupDone = true; } catch (RemoteException e) { if (listener != null) { listener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION, "RemoteException while setting up in-app billing.")); } Logger.e("RemoteException while setting up in-app billing", e); return; } if (listener != null) { listener.onIabSetupFinished(new IabResult(RESULT_OK, "Setup successful.")); } } }; Intent serviceIntent = getServiceIntent(); final List<ResolveInfo> infoList = mContext.getPackageManager().queryIntentServices(serviceIntent, 0); if (infoList != null && !infoList.isEmpty()) { // service available to handle that Intent mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); } else { // no service available to handle that Intent if (listener != null) { listener.onIabSetupFinished( new IabResult(RESULT_BILLING_UNAVAILABLE, "Billing service unavailable on device.")); } } }
From source file:com.zentri.otademo.ConnectActivity.java
private void initServiceConnection() { mBound = false;//www . j a va 2 s . c om mUnbinding = false; mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName className, IBinder service) { Log.d(TAG, "Connected to service"); cancelTimeout(mServiceConnectionTimeoutTask); ZentriOSBLEService.LocalBinder binder = (ZentriOSBLEService.LocalBinder) service; mService = binder.getService(); mBound = true; if (requirementsMet()) { startScan(); } } @Override public void onServiceDisconnected(ComponentName arg0) { mBound = false; if (!mUnbinding) { //connection lost unexpectedly showErrorDialog(R.string.error_connection_lost_message, !FINISH_ON_CLOSE); } mUnbinding = false; } }; }
From source file:com.google.android.car.kitchensink.radio.RadioTestFragment.java
private void init() { mCar = Car.createCar(getContext(), new ServiceConnection() { @Override/*from w ww . j a v a 2 s . co m*/ public void onServiceConnected(ComponentName name, IBinder service) { try { mCarAudioManager = (CarAudioManager) mCar.getCarManager(Car.AUDIO_SERVICE); mRadioAudioAttrib = mCarAudioManager .getAudioAttributesForCarUsage(CarAudioManager.CAR_AUDIO_USAGE_RADIO); } catch (CarNotConnectedException e) { Log.e(TAG, "Car not connected", e); } } @Override public void onServiceDisconnected(ComponentName name) { } }); mCar.connect(); mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); initializeRadio(); }
From source file:com.zentri.zentri_ble_command_demo.DeviceInfoActivity.java
private void initServiceConnection() { mConnection = new ServiceConnection() { @Override/*from w w w.j a v a2 s. c o m*/ public void onServiceConnected(ComponentName className, IBinder service) { ZentriOSBLEService.LocalBinder binder = (ZentriOSBLEService.LocalBinder) service; mService = binder.getService(); mBound = true; mZentriOSBLEManager = mService.getManager(); mZentriOSBLEManager.setMode(ZentriOSBLEManager.MODE_COMMAND_REMOTE); mZentriOSBLEManager.setSystemCommandMode(CommandMode.MACHINE); initGPIOs(); updateValues(); } @Override public void onServiceDisconnected(ComponentName arg0) { mBound = false; } }; }
From source file:systems.byteswap.publicstream.MainActivity.java
void createWithoutFragment() { Intent mMediaServiceIntent;/* w w w.j a v a 2 s . c o m*/ // add the fragment dataFragment = new MainFragment(); mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { //mService = ((LocalBinder<MediaService>) service).getService(); mService = MediaService.getService(service); dataFragment.setMediaService(mService); } public void onServiceDisconnected(ComponentName className) { } }; dataFragment.setMediaConnection(mConnection); //start the mediaplayer service mMediaServiceIntent = new Intent(this, MediaService.class); startService(mMediaServiceIntent); bindService(mMediaServiceIntent, mConnection, Context.BIND_IMPORTANT); dataFragment.setMediaServiceIntent(mMediaServiceIntent); }
From source file:com.soomla.billing.IabHelper.java
/** * Starts the setup process. This will start up the setup process asynchronously. * You will be notified through the listener when the setup process is complete. * This method is safe to call from a UI thread. * * @param listener The listener to notify when the setup process is complete. *///from ww w. ja v a 2 s . c o m public void startSetup(final OnIabSetupFinishedListener listener) { // If already set up, can't do it again. if (mSetupDone) throw new IllegalStateException("IAB helper is already set up."); // Connection to IAB service StoreUtils.LogDebug(TAG, "Starting in-app billing setup."); mServiceConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { StoreUtils.LogDebug(TAG, "Billing service disconnected."); mService = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { StoreUtils.LogDebug(TAG, "Billing service connected."); mService = IInAppBillingService.Stub.asInterface(service); String packageName = SoomlaApp.getAppContext().getPackageName(); try { StoreUtils.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 != BILLING_RESPONSE_RESULT_OK) { if (listener != null) { listener.onIabSetupFinished( new IabResult(response, "Error checking for billing v3 support.")); } // if in-app purchases aren't supported, neither are subscriptions. mSubscriptionsSupported = false; return; } StoreUtils.LogDebug(TAG, "In-app billing version 3 supported for " + packageName); // check for v3 subscriptions support response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { StoreUtils.LogDebug(TAG, "Subscriptions AVAILABLE."); mSubscriptionsSupported = true; } else { StoreUtils.LogDebug(TAG, "Subscriptions NOT AVAILABLE. Response: " + response); } mSetupDone = true; } catch (RemoteException e) { if (listener != null) { listener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION, "RemoteException while setting up in-app billing.")); } e.printStackTrace(); return; } if (listener != null) { listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful.")); } } }; Intent serviceIntent = new Intent("ir.cafebazaar.pardakht.InAppBillingService.BIND"); if (!SoomlaApp.getAppContext().getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) { // service available to handle that Intent SoomlaApp.getAppContext().bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); } else { // no service available to handle that Intent if (listener != null) { listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE, "Billing service unavailable on device.")); } } }