List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter
public static synchronized BluetoothAdapter getDefaultAdapter()
From source file:cordova.plugins.Diagnostic.java
public boolean isBluetoothEnabled() { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); boolean result = mBluetoothAdapter != null && mBluetoothAdapter.isEnabled(); return result; }
From source file:com.jtechme.apphub.FDroidApp.java
@TargetApi(18) private BluetoothAdapter getBluetoothAdapter() { // to use the new, recommended way of getting the adapter // http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html if (Build.VERSION.SDK_INT < 18) { return BluetoothAdapter.getDefaultAdapter(); }//from www. j ava2s.c o m return ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter(); }
From source file:de.schildbach.wallet.ui.ReportIssueDialogFragment.java
private static String bluetoothMac() { try {//from w ww .ja v a 2 s . c om return Bluetooth.getAddress(BluetoothAdapter.getDefaultAdapter()); } catch (final Exception x) { return x.getMessage(); } }
From source file:org.metawatch.manager.MetaWatchService.java
@TargetApi(10) private boolean connect() { try {//from ww w. j av a 2 s .co m if (!Preferences.loaded) loadPreferences(this); MetaWatchService.fakeWatch = false; if (Preferences.watchMacAddress.equals("DIGITAL")) { MetaWatchService.fakeWatch = true; MetaWatchService.watchType = WatchType.DIGITAL; } if (Preferences.watchMacAddress.equals("ANALOG")) { MetaWatchService.fakeWatch = true; MetaWatchService.watchType = WatchType.ANALOG; } if (Preferences.logging) Log.d(MetaWatchStatus.TAG, "Remote device address: '" + Preferences.watchMacAddress + "'"); if (!MetaWatchService.fakeWatch) { if (bluetoothAdapter == null) bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice(Preferences.watchMacAddress); int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (Preferences.skipSDP) { Method method; if (Preferences.insecureBtSocket && currentapiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { method = bluetoothDevice.getClass().getMethod("createInsecureRfcommSocket", new Class[] { int.class }); } else { method = bluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); } bluetoothSocket = (BluetoothSocket) method.invoke(bluetoothDevice, 1); } else { UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); if (Preferences.insecureBtSocket && currentapiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(uuid); } else { bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(uuid); } } bluetoothAdapter.cancelDiscovery(); bluetoothSocket.connect(); inputStream = bluetoothSocket.getInputStream(); outputStream = bluetoothSocket.getOutputStream(); } connectionState = ConnectionState.CONNECTED; setPreviousConnectionState(this, true); updateNotification(); Protocol.getInstance(MetaWatchService.this).getDeviceType(); NavigationManagement.processWatchConnection(this); // Unblock the message protocol queue, and the notification queue. mPauseQueue.open(); return true; } catch (IOException ioexception) { if (Preferences.logging) Log.d(MetaWatchStatus.TAG, ioexception.toString()); } catch (SecurityException e) { if (Preferences.logging) Log.d(MetaWatchStatus.TAG, e.toString()); } catch (NoSuchMethodException e) { if (Preferences.logging) Log.d(MetaWatchStatus.TAG, e.toString()); } catch (IllegalArgumentException e) { if (Preferences.logging) Log.d(MetaWatchStatus.TAG, e.toString()); } catch (IllegalAccessException e) { if (Preferences.logging) Log.d(MetaWatchStatus.TAG, e.toString()); } catch (InvocationTargetException e) { if (Preferences.logging) Log.d(MetaWatchStatus.TAG, e.toString()); } catch (NullPointerException e) { if (Preferences.logging) Log.d(MetaWatchStatus.TAG, e.toString()); } finally { } return false; }
From source file:flex.android.magiccube.activity.ActivityBattleMode.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mode_battle); btMoveBack = (ImageButton) findViewById(R.id.bt_battle_moveback); btMoveForward = (ImageButton) findViewById(R.id.bt_battle_moveforward); btStartOb = (ImageButton) findViewById(R.id.bt_battle_startob); clock = (ImageView) findViewById(R.id.img_battle_clock); txtTime = (TextView) findViewById(R.id.txt_battle_time); txtNStep = (TextView) findViewById(R.id.txt_battle_nStep); img_nstep = (ImageView) findViewById(R.id.img_battle_nstep); progress = (SeekBar) findViewById(R.id.sbar_battle_timer); /*/* ww w .ja v a 2 s . c o m*/ * clock.setVisibility(View.VISIBLE); * btMoveForward.setVisibility(View.VISIBLE); * btMoveBack.setVisibility(View.VISIBLE); */ glView = (ViewBattleMode) findViewById(R.id.game_view_battle); glView.SetOnTimerListener(this); // glView.setOnStateListener(this); glView.SetOnStepListener(this); glView.SetMessageSender(this); glView.SetDrawCube(false); glView.setOnStateListener(this); glView2 = (ViewBattleMode) findViewById(R.id.game_view_battle2); glView2.SetCanMove(false); btMoveBack.setOnClickListener(buttonListener); btMoveForward.setOnClickListener(buttonListener); btStartOb.setOnClickListener(buttonListener); float fontsize = 25.f; Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/Angies New House.ttf"); txtTime.setTypeface(typeFace); txtTime.setTextColor(Color.GRAY); txtTime.setTextSize(fontsize); txtNStep.setTypeface(typeFace); txtNStep.setTextColor(Color.GRAY); txtNStep.setTextSize(fontsize); State = OnStateListener.NONE; BgVolume = MagiccubePreference.GetPreference(MagiccubePreference.BgVolume, this); LinearBgVolume = MusicPlayThread.GetLinearVolume(BgVolume); GamingbgmPlayer = MediaPlayer.create(this, R.raw.bg2); ObservingbgmPlayer = MediaPlayer.create(this, R.raw.bg); FinishbgmPlayer = MediaPlayer.create(this, R.raw.finish); GamingbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume); ObservingbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume); FinishbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume); Init(); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { Toast.makeText(this, "...", Toast.LENGTH_LONG).show(); finish(); return; } WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); width = wm.getDefaultDisplay().getWidth(); height = wm.getDefaultDisplay().getHeight(); layout_moveforward = (LinearLayout) findViewById(R.id.layout_battle_moveforward); layout_moveback = (LinearLayout) findViewById(R.id.layout_battle_moveback); int buttonwidth = width / 5; int buttonheight = height / 13; LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(buttonwidth, buttonheight); btMoveForward.setLayoutParams(parms); btMoveBack.setLayoutParams(parms); layout_moveforward.setPadding(width / 2 - buttonwidth / 2, height - buttonheight, 0, 0); layout_moveback.setPadding(width / 15, height - buttonheight, 0, 0); }
From source file:com.cardiograph.view.BLEActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SELECT_DEVICE: //When the DeviceListActivity return, with the selected device address if (resultCode == Activity.RESULT_OK && data != null) { String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting"); mService.connect(deviceAddress); }//from w ww .jav a 2 s .c o m break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); finish(); } break; default: Log.e(TAG, "wrong request code"); break; } }
From source file:hashengineering.digitalcoin.wallet.ui.SendCoinsFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);/* w w w . j a va 2 s . com*/ bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND); backgroundThread.start(); backgroundHandler = new Handler(backgroundThread.getLooper()); btcPrecision = Integer.parseInt( prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION)); }
From source file:cordova.plugins.Diagnostic.java
public static boolean setBluetoothState(boolean enable) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); boolean isEnabled = bluetoothAdapter.isEnabled(); if (enable && !isEnabled) { return bluetoothAdapter.enable(); } else if (!enable && isEnabled) { return bluetoothAdapter.disable(); }/* ww w. jav a 2 s.c om*/ return true; }
From source file:com.pileproject.drive.setting.machine.BluetoothMachineSelectFragment.java
private void subscribeBluetoothDiscovery() { mSubscriptions.add(/*w w w . j ava 2 s. co m*/ RxBluetoothBroadcastReceiver.bluetoothDeviceFound(getActivity()).subscribeOn(Schedulers.newThread()) // should run on UI thread (main thread) to change UI components .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Intent>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(Intent intent) { BluetoothDevice bluetoothDevice = intent .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (bluetoothDevice.getBondState() == BluetoothDevice.BOND_BONDED) { return; } BluetoothMachineListAdapter adapter = (BluetoothMachineListAdapter) mNewDevicesListView .getAdapter(); if (adapter.contains(bluetoothDevice)) { return; } adapter.add(bluetoothDevice); adapter.notifyDataSetChanged(); } })); mSubscriptions.add(RxBluetoothBroadcastReceiver.bluetoothDiscoveryFinished(getActivity()) .observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.newThread()) .subscribe(new Observer<Intent>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(Intent intent) { // enable continuous discovering BluetoothAdapter.getDefaultAdapter().startDiscovery(); } })); }
From source file:com.pileproject.drive.setting.machine.BluetoothMachineSelectFragment.java
private void updatePairedList() { BluetoothMachineListAdapter listAdapter = (BluetoothMachineListAdapter) mPairedDevicesListView.getAdapter(); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); listAdapter.clear();/*from ww w. java2 s. c o m*/ listAdapter.addAll(bluetoothAdapter.getBondedDevices()); String macAddress = MachinePreferences.get(getActivity()).getMacAddress(); if (BluetoothAdapter.checkBluetoothAddress(macAddress)) { BluetoothDevice device = bluetoothAdapter.getRemoteDevice(macAddress); if (listAdapter.contains(device)) { mPairedDevicesListView.setItemChecked(listAdapter.getPosition(device), true); } } }