List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter
public static synchronized BluetoothAdapter getDefaultAdapter()
From source file:com.manuelmazzuola.speedtogglebluetooth.service.MonitorSpeed.java
private void starTimer() { countDownTimer = new CountDownTimer(30000, 30000) { public void onTick(long millisUntilFinished) { }/*from ww w . j a v a2s. c o m*/ public void onFinish() { changeMessage(DEFAULT_MESSAGE); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.disable(); } }.start(); }
From source file:nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebblePairingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pebble_pairing); message = (TextView) findViewById(R.id.pebble_pair_message); Intent intent = getIntent();// ww w .j av a 2 s. co m GBDeviceCandidate candidate = intent.getParcelableExtra(DeviceCoordinator.EXTRA_DEVICE_CANDIDATE); if (candidate != null) { macAddress = candidate.getMacAddress(); } if (macAddress == null) { Toast.makeText(this, getString(R.string.message_cannot_pair_no_mac), Toast.LENGTH_SHORT).show(); returnToPairingActivity(); return; } mBtDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddress); if (mBtDevice == null) { GB.toast(this, "No such Bluetooth Device: " + macAddress, Toast.LENGTH_LONG, GB.ERROR); returnToPairingActivity(); return; } isLEPebble = mBtDevice.getType() == BluetoothDevice.DEVICE_TYPE_LE; GBDevice gbDevice = null; if (isLEPebble) { if (mBtDevice.getName().startsWith("Pebble-LE ") || mBtDevice.getName().startsWith("Pebble Time LE ")) { if (!GBApplication.getPrefs().getBoolean("pebble_force_le", false)) { GB.toast(this, "Please switch on \"Always prefer BLE\" option in Pebble settings before pairing you Pebble LE", Toast.LENGTH_LONG, GB.ERROR); returnToPairingActivity(); return; } gbDevice = getMatchingParentDeviceFromDB(mBtDevice); if (gbDevice == null) { return; } } } startPairing(gbDevice); }
From source file:com.pileproject.drive.setting.machine.BluetoothMachineSelectFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); resizeDialog();/*from ww w. j a va 2s .c o m*/ mPairedDevicesListView.setAdapter(new BluetoothMachineListAdapter(getActivity(), R.layout.view_bluetooth_machine_list, new LinkedList<BluetoothDevice>())); mPairedDevicesListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); mPairedDevicesListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ListView listView = (ListView) parent; BluetoothDevice bluetoothDevice = (BluetoothDevice) listView.getItemAtPosition(position); MachinePreferences.get(getActivity()).setMacAddress(bluetoothDevice.getAddress()); Toast.makeText(getActivity(), getString(R.string.setting_bluetoothMachineSelect_toast_setDefault) + "\n" + bluetoothDevice.getName(), Toast.LENGTH_LONG).show(); } }); mNewDevicesListView.setAdapter(new BluetoothMachineListAdapter(getActivity(), R.layout.view_bluetooth_machine_list, new LinkedList<BluetoothDevice>())); mNewDevicesListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ListView listView = (ListView) parent; BluetoothDevice bluetoothDevice = (BluetoothDevice) listView.getItemAtPosition(position); final String bluetoothDeviceName = bluetoothDevice.getName(); ProgressDialogFragment.showDialog(getActivity(), getChildFragmentManager(), R.string.setting_bluetoothMachineSelect_progress_connecting_title, R.string.setting_bluetoothMachineSelect_progress_connecting_message, "tag"); // cancel scanning process because this is very heavyweight BluetoothAdapter.getDefaultAdapter().cancelDiscovery(); mSubscriptions.add(RxBluetoothConnector.pairing(bluetoothDevice) .observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<BluetoothDevice>() { @Override public void onCompleted() { updatePairedList(); BluetoothAdapter.getDefaultAdapter().startDiscovery(); ProgressDialogFragment.dismissDialog(); } @Override public void onError(Throwable e) { BluetoothAdapter.getDefaultAdapter().startDiscovery(); Toast.makeText(getActivity(), getString(R.string.setting_bluetoothMachineSelect_toast_cannotConnect, bluetoothDeviceName), Toast.LENGTH_LONG).show(); ProgressDialogFragment.dismissDialog(); } @Override public void onNext(BluetoothDevice bluetoothDevice) { MachinePreferences.get(getActivity()).setMacAddress(bluetoothDevice.getAddress()); Toast.makeText(getActivity(), getString(R.string.setting_bluetoothMachineSelect_toast_setDefault, bluetoothDeviceName), Toast.LENGTH_LONG).show(); BluetoothMachineListAdapter adapter = (BluetoothMachineListAdapter) mNewDevicesListView .getAdapter(); adapter.remove(bluetoothDevice); } })); } }); }
From source file:org.hopestarter.wallet.ui.RequestCoinsFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractBindServiceActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.config = application.getConfiguration(); this.wallet = application.getWallet(); this.loaderManager = getLoaderManager(); this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); this.nfcAdapter = NfcAdapter.getDefaultAdapter(activity); }
From source file:kr.ac.knu.odego.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from www . jav a 2 s . c o m mContentsLayout = (CoordinatorLayout) findViewById(R.id.contents_layout); // tab_main1 = ViewUtil.iconText(ViewUtil.drawable(this, R.drawable.main_on_btn1), ""); tab_main2 = ViewUtil.iconText(ViewUtil.drawable(this, R.drawable.main_on_btn2), ""); tab_main3 = ViewUtil.iconText(ViewUtil.drawable(this, R.drawable.main_on_btn3), ""); tab_main4 = ViewUtil.iconText(ViewUtil.drawable(this, R.drawable.main_on_btn4), ""); tab_off_main1 = ViewUtil.iconText(ViewUtil.drawable(this, R.drawable.main_off_btn1), ""); tab_off_main2 = ViewUtil.iconText(ViewUtil.drawable(this, R.drawable.main_off_btn2), ""); tab_off_main3 = ViewUtil.iconText(ViewUtil.drawable(this, R.drawable.main_off_btn3), ""); tab_off_main4 = ViewUtil.iconText(ViewUtil.drawable(this, R.drawable.main_off_btn4), ""); // fragment ? mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mSectionsPagerAdapter.registerDataSetObserver(mObserver); mSectionsPagerAdapter.addFragment(new FavoriteFragment(), tab_main1); mSectionsPagerAdapter.addFragment(new RouteSearchFragment(), tab_off_main2); mSectionsPagerAdapter.addFragment(new BusStopSearchFragment(), tab_off_main3); mSectionsPagerAdapter.addFragment(new TheOtherFragment(), tab_off_main4); mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.addOnPageChangeListener(this); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); progressLayout = (LinearLayout) findViewById(R.id.progress_layout); // ?? drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); // ? mBtAdapter = BluetoothAdapter.getDefaultAdapter(); // mBtAdapter.enable(); // realm mRealm = Realm.getDefaultInstance(); mSettingRealm = Realm.getInstance(OdegoApplication.getSettingRealmConfig()); mSetting = mSettingRealm.where(Setting.class).findFirst(); if (mSetting == null) { mSettingRealm.executeTransactionAsync(new Realm.Transaction() { @Override public void execute(Realm realm) { Setting setting = realm.createObject(Setting.class); setting.setRequestRemainCount(2); } }, new Realm.Transaction.OnSuccess() { @Override public void onSuccess() { mSetting = mSettingRealm.where(Setting.class).findFirst(); } }); } // Parser DB ? new DataBaseCreateAsyncTask().execute(false); }
From source file:cc.mintcoin.wallet.ui.RequestCoinsFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractBindServiceActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.config = application.getConfiguration(); this.wallet = application.getWallet(); this.loaderManager = getLoaderManager(); this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE); this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); }
From source file:com.lauszus.launchpadflightcontrollerandroid.app.LaunchPadFlightControllerActivity.java
@Override @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_pad_flight_controller); // Get local Bluetooth adapter if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); else// ww w. j a v a 2 s. c o m mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { showToast("Bluetooth is not available", Toast.LENGTH_LONG); finish(); return; } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Create the adapter that will return a fragment for each of the primary sections of the app. mViewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mViewPagerAdapter); TabLayout mTabLayout = (TabLayout) findViewById(R.id.tabs); mTabLayout.setupWithViewPager(mViewPager); mTabLayout.setOnTabSelectedListener(this); mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL); mTabLayout.setTabMode(TabLayout.MODE_FIXED); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Keep the screen on }
From source file:com.github.akinaru.bleremote.activity.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(layoutId);//ww w .ja v a 2 s.co m if (Build.VERSION.SDK_INT >= 21) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark)); } // Set a Toolbar to replace the ActionBar. toolbar = (Toolbar) findViewById(R.id.toolbar_item); setSupportActionBar(toolbar); getSupportActionBar().setTitle(getResources().getString(R.string.bt_device_title)); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.inflateMenu(R.menu.toolbar_menu); // Find our drawer view mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawerToggle = setupDrawerToggle(); mDrawer.setDrawerListener(drawerToggle); nvDrawer = (NavigationView) findViewById(R.id.nvView); // Setup drawer view setupDrawerContent(nvDrawer); //setup bluetooth if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, getResources().getString(R.string.ble_not_supported), Toast.LENGTH_SHORT).show(); finish(); } //setup bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); }
From source file:org.mobisocial.corral.CorralClient.java
private Uri getFileOverBluetooth(DbUser user, SignedObj obj) throws IOException { String macStr = DbContactAttributes.getAttribute(mContext, user.getLocalId(), Contact.ATTR_BT_MAC); if (macStr == null) { throw new IOException("No bluetooth mac address for user"); }//from w w w.j av a2 s .c o m String uuidStr = DbContactAttributes.getAttribute(mContext, user.getLocalId(), Contact.ATTR_BT_CORRAL_UUID); if (uuidStr == null) { throw new IOException("No corral uuid for user"); } UUID uuid = UUID.fromString(uuidStr); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice device = adapter.getRemoteDevice(macStr); BluetoothSocket socket; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) { socket = device.createInsecureRfcommSocketToServiceRecord(uuid); } else { socket = device.createRfcommSocketToServiceRecord(uuid); } // TODO: // Custom wire protocol, look for header bits to map to protocol handler. Log.d(TAG, "BJD BLUETOOTH CORRAL NOT READY: can't pull file over bluetooth."); return null; }
From source file:ch.ethz.twimight.net.opportunistic.ScanningService.java
@Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); handler = new Handler(); // set up Bluetooth bluetoothHelper = new BluetoothComms(this, mHandler); bluetoothHelper.start();/* w ww. j a va2 s . c om*/ dbHelper = new MacsDBHelper(getApplicationContext()); dbHelper.open(); // sdCard helper sdCardHelper = new SDCardHelper(); // htmldb helper htmlDbHelper = new HtmlPagesDbHelper(getApplicationContext()); htmlDbHelper.open(); mBtAdapter = BluetoothAdapter.getDefaultAdapter(); }