List of usage examples for android.content ServiceConnection ServiceConnection
ServiceConnection
From source file:edu.umich.oasis.client.OASISConnection.java
public static ServiceConnection bind(final Context context, final Callback callback) { final ServiceConnection connection = new ServiceConnection() { private OASISConnection conn; @Override//w ww . ja v a 2s. c o m public void onServiceConnected(ComponentName componentName, IBinder iBinder) { IOASISService service = IOASISService.Stub.asInterface(iBinder); conn = new OASISConnection(context, this, service); try { callback.onConnect(conn); } catch (Exception e) { Log.e(TAG, "Unhandled exception in onConnect", e); } } @Override public void onServiceDisconnected(ComponentName componentName) { Log.e(TAG, "Lost Binder connection to OASIS"); if (callback instanceof DisconnectCallback) { try { ((DisconnectCallback) callback).onDisconnect(conn); } catch (Exception e) { Log.e(TAG, "Unhandled exception in onDisconnect", e); } } conn.closeInternal(); } }; Intent serviceIntent = new Intent(); serviceIntent.setComponent(OASISFramework.getServiceComponent(context)); if (context.bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE | Context.BIND_ADJUST_WITH_ACTIVITY | Context.BIND_ABOVE_CLIENT | Context.BIND_IMPORTANT)) { return connection; } else { return null; } }
From source file:net.kourlas.voipms_sms.Billing.java
/** * Initializes an instance of the Billing class. * * @param applicationContext The application context. *//*from w w w.j ava2 s .c o m*/ public Billing(Context applicationContext) { this.applicationContext = applicationContext; serviceConnection = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { billingService = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { billingService = IInAppBillingService.Stub.asInterface(service); } }; Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); applicationContext.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE); }
From source file:com.tangrainc.inappbilling.InAppBillingHelper.java
public InAppBillingHelper(Context context, String[] productIdentifiers) { _executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()); _productIdentifiers = productIdentifiers; _context = context;//from ww w . j a v a 2 s . co m ServiceConnection _serviceConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { Log.d(TAG, "Billing Service disconnected."); _service = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { Log.d(TAG, "Billing Service connected."); _service = IInAppBillingService.Stub.asInterface(service); } }; Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); _context.bindService(serviceIntent, _serviceConn, Context.BIND_AUTO_CREATE); }
From source file:com.google.android.apps.tvremote.CoreServiceActivity.java
/** * Opens the connection to the underlying service. */// w w w . ja v a 2 s. com private void connectToService() { Log.w("hwang-tvremote", "CoreServiceActivity : new ServiceConnection()"); serviceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder service) { coreService = ((CoreService.LocalBinder) service).getService(); runQueuedRunnables(); onServiceAvailable(coreService); Log.w("hwang-tvremote", "CoreServiceActivity : callback onServiceConnected from CoreService"); } public void onServiceDisconnected(ComponentName name) { onServiceDisconnecting(coreService); coreService = null; Log.w("hwang-tvremote", "CoreServiceActivity : callback onServiceDisconnected from CoreService"); } }; Log.w("hwang-tvremote", "CoreServiceActivity : starting bind CoreService"); Intent intent = new Intent(this, CoreService.class); bindService(intent, serviceConnection, BIND_AUTO_CREATE); }
From source file:com.gigathinking.simpleapplock.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_main); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mServiceConn = new ServiceConnection() { @Override/*from www. j a va2 s. com*/ public void onServiceConnected(ComponentName name, IBinder service) { mService = IInAppBillingService.Stub.asInterface(service); new CheckPurchases().execute(); } @Override public void onServiceDisconnected(ComponentName name) { mService = null; } }; bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE); if (mPrefs.getString("welcome_shown", null) == null) { startActivity(new Intent(this, Welcome.class)); } mAppListData = new AppListData(this); mAppListData.init(); if (!mPrefs.getBoolean(getString(R.string.register_complete), false)) { new Register().execute(); } mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); if (savedInstanceState != null) { return; } if (mPrefs.getBoolean(AppLockApplication.LOCKSET, false)) { if (mPrefs.getString(AppLockApplication.LOCKTYPE, "").equals(AppLockApplication.LOCKTYPE_PIN)) { startActivityForResult( new Intent(this, UnlockWithPIN.class).putExtra(AppLockApplication.UNLOCK_SELF, true), 23); } if (mPrefs.getString(AppLockApplication.LOCKTYPE, "").equals(AppLockApplication.LOCKTYPE_GESTURE)) { startActivityForResult( new Intent(this, UnlockWithGesture.class).putExtra(AppLockApplication.UNLOCK_SELF, true), 23); } if (mPrefs.getString(AppLockApplication.LOCKTYPE, "").equals(AppLockApplication.LOCKTYPE_PATTERN)) { Intent intent = new Intent(LockPatternActivity.ACTION_COMPARE_PATTERN, null, this, LockPatternActivity.class); intent.putExtra(LockPatternActivity.EXTRA_PATTERN, Settings.Security.getPattern(this)); intent.putExtra(LockPatternActivity.EXTRA_INTENT_ACTIVITY_FORGOT_PATTERN, new Intent(this, ResetUnlockMethod.class)); startActivityForResult(intent, 23); } } Intent intent = new Intent(this, AppLaunchDetectorService.class); startService(intent); }
From source file:android.car.cluster.sample.MainClusterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = new Intent(this, SampleClusterServiceImpl.class); intent.setAction(LOCAL_BINDING_ACTION); bindService(intent, new ServiceConnection() { @Override/*from w w w. j a v a2s .c o m*/ public void onServiceConnected(ComponentName name, IBinder service) { Log.i(TAG, "onServiceConnected, name: " + name + ", service: " + service); mService = ((SampleClusterServiceImpl.LocalBinder) service).getService(); mService.registerListener(MainClusterActivity.this); } @Override public void onServiceDisconnected(ComponentName name) { Log.i(TAG, "onServiceDisconnected, name: " + name); mService = null; } }, BIND_AUTO_CREATE); mNavButton = findViewById(R.id.btn_nav); mPhoneButton = findViewById(R.id.btn_phone); mCarInfoButton = findViewById(R.id.btn_car_info); mMusicButton = findViewById(R.id.btn_music); mTextOverlay = findViewById(R.id.text_overlay); registerFacets(new Facet<>(mNavButton, 0, NavigationFragment.class), new Facet<>(mPhoneButton, 1, PhoneFragment.class), new Facet<>(mMusicButton, 2, MusicFragment.class), new Facet<>(mCarInfoButton, 3, CarInfoFragment.class)); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(new ClusterPageAdapter(getSupportFragmentManager())); mNavButton.requestFocus(); }
From source file:de.petendi.ethereum.android.EthereumAndroid.java
public EthereumAndroid(Context context, EthereumAndroidCallback callback) { this.context = context; this.callback = callback; objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); EthereumAndroidService.responseHandler = new CallbackHandler(); packageName = context.getApplicationInfo().packageName; Intent intent = new Intent("de.petendi.ethereum.android.action.BIND_API"); intent.setPackage(EthereumAndroidFactory.PACKAGENAME); serviceConnection = new ServiceConnection() { @Override/* www. j a v a2 s . com*/ public void onServiceConnected(ComponentName componentName, IBinder iBinder) { binder = IEthereumService.Stub.asInterface(iBinder); } @Override public void onServiceDisconnected(ComponentName componentName) { binder = null; } }; context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE); }
From source file:org.connectbot.EditHostActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHostDb = HostDatabase.get(this); mPubkeyDb = PubkeyDatabase.get(this); mTerminalConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { TerminalManager bound = ((TerminalManager.TerminalBinder) service).getService(); mBridge = bound.getConnectedBridge(mHost); }//from w ww . j a v a2 s . c om public void onServiceDisconnected(ComponentName name) { mBridge = null; } }; long hostId = getIntent().getLongExtra(EXTRA_EXISTING_HOST_ID, NO_HOST_ID); mIsCreating = hostId == NO_HOST_ID; mHost = mIsCreating ? null : mHostDb.findHostById(hostId); // Note that the lists must be explicitly declared as ArrayLists because Bundle only accepts // ArrayLists of Strings. ArrayList<String> pubkeyNames = new ArrayList<>(); ArrayList<String> pubkeyValues = new ArrayList<>(); // First, add default pubkey names and values (e.g., "use any" and "don't use any"). TypedArray defaultPubkeyNames = getResources().obtainTypedArray(R.array.list_pubkeyids); for (int i = 0; i < defaultPubkeyNames.length(); i++) { pubkeyNames.add(defaultPubkeyNames.getString(i)); } TypedArray defaultPubkeyValues = getResources().obtainTypedArray(R.array.list_pubkeyids_value); for (int i = 0; i < defaultPubkeyValues.length(); i++) { pubkeyValues.add(defaultPubkeyValues.getString(i)); } // Now, add pubkeys which have been added by the user. for (CharSequence cs : mPubkeyDb.allValues(PubkeyDatabase.FIELD_PUBKEY_NICKNAME)) { pubkeyNames.add(cs.toString()); } for (CharSequence cs : mPubkeyDb.allValues("_id")) { pubkeyValues.add(cs.toString()); } setContentView(R.layout.activity_edit_host); FragmentManager fm = getSupportFragmentManager(); HostEditorFragment fragment = (HostEditorFragment) fm.findFragmentById(R.id.fragment_container); if (fragment == null) { fragment = HostEditorFragment.newInstance(mHost, pubkeyNames, pubkeyValues); getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, fragment).commit(); } defaultPubkeyNames.recycle(); defaultPubkeyValues.recycle(); }
From source file:de.tu_berlin.snet.commstat.SensorFragment.java
public SensorFragment() { handle = new Handler(); funfMgrConn = new ServiceConnection() { @Override/*w w w . j a va 2 s .c om*/ public void onServiceConnected(ComponentName name, IBinder service) { funfMgr = ((FunfManager.LocalBinder) service).getManager(); pipeline = (BasicPipeline) funfMgr.getRegisteredPipeline(PIPELINE_NAME); wifiProbe = funfMgr.getGson().fromJson(new JsonObject(), WifiProbe.class); wifiProbe.registerPassiveListener(SensorFragment.this); Log.i(TAG, "Funf service connected"); } @Override public void onServiceDisconnected(ComponentName name) { funfMgr = null; pipeline = null; Log.i(TAG, "Funf service disconnected"); } }; }
From source file:com.ubuntuone.android.files.activity.GalleryActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_gallery); mHandler = new Handler(); mReceiver = new DetachableResultReceiver(mHandler); galleryFragment = (GalleryFragment) getSupportFragmentManager().findFragmentById(R.id.galleryFragment); directoryResourcePath = getIntent().getStringExtra("directoryResourcePath"); firstImageKey = getIntent().getStringExtra("firstImageKey"); showGallery(directoryResourcePath, firstImageKey); conn = new ServiceConnection() { @Override//from w ww. j a v a2 s . c o m public void onServiceConnected(ComponentName name, IBinder service) { boundService = ((UpDownService.LocalBinder) service).getService(); boundService.registerDownloadListener(GalleryActivity.this); } @Override public void onServiceDisconnected(ComponentName name) { boundService = null; } }; }