Refine search
@Override public synchronized void initAndCheckEligibility() throws ScannerException { if (Build.VERSION.SDK_INT < ScannerFactory.OS_VERSION_LOLLIPOP) { throw new ScannerException(ScannerException.Type.NOT_SUPPORTED); } if (!Validate.hasBluetoothPermission(context)) { throw new ScannerException(ScannerException.Type.PERMISSION_DENIED); } if (!Validate.hasLocationPermission(context)) { throw new ScannerException(ScannerException.Type.PERMISSION_DENIED); } bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { throw new ScannerException(ScannerException.Type.DISABLED); } bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bluetoothLeScanner == null) { throw new ScannerException(ScannerException.Type.UNKNOWN_ERROR); } }
if (btAdapter.isEnabled()) { SharedPreferences prefs_btdev = getSharedPreferences("btdev", 0); String btdevaddr=prefs_btdev.getString("btdevaddr","?"); BluetoothDevice device = btAdapter.getRemoteDevice(btdevaddr); UUID SERIAL_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); // bluetooth serial port service
Set<BluetoothDevice> pairedDevice = bluetoothAdapter.getBondedDevices(); if(pairedDevice.size()>0) public void onReceive(Context context, Intent intent) { Message msg = Message.obtain(); String action = intent.getAction(); if(BluetoothDevice.ACTION_FOUND.equals(action)){ Toast.makeText(context, "ACTION_FOUND", Toast.LENGTH_SHORT).show(); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); try IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND); BluetoothDemo.this.registerReceiver(myReceiver, intentFilter); bluetoothAdapter.startDiscovery(); if(!bluetoothAdapter.isEnabled()) bluetoothAdapter.enable(); Log.i("Log", "Bluetooth is Enabled"); if(bluetoothAdapter.isEnabled()) bluetoothAdapter.disable(); discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); startActivity(discoverableIntent); Log.i("Log", "Discoverable ");
public static boolean setBluetooth(boolean enable) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); boolean isEnabled = bluetoothAdapter.isEnabled(); if (enable && !isEnabled) { return bluetoothAdapter.enable(); } else if(!enable && isEnabled) { return bluetoothAdapter.disable(); } // No need to change bluetooth state return true; }
public void askUserToEnableBluetoothIfNeeded() { if (isBluetoothLeSupported() && (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled())) { final Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); mActivity.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } }
/** * This will ensure that all router services are aware that there are no valid router services running and should start up */ private void wakeUpRouterServices(){ if(BluetoothAdapter.getDefaultAdapter()!=null && BluetoothAdapter.getDefaultAdapter().isEnabled()){ Intent intent = new Intent(TransportConstants.START_ROUTER_SERVICE_ACTION); intent.putExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA, true); AndroidTools.sendExplicitBroadcast(context,intent,null); } } public ComponentName getService(){
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) { //Enable if disabled Intent localIntent; localIntent = new Intent(); localIntent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); localIntent.addCategory("android.intent.category.ALTERNATIVE"); localIntent.setData(Uri.parse("4")); getBroadcast(paramContext, 0, localIntent, 0).send(); }
private void initBluetooth() { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { finish(); return; } if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, 2333); } }
public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bytes) { Asset asset = DataManager.getAssetForMACAddress(bluetoothDevice.getAddress()); handleDiscoveredAsset(asset); bluetoothAdapter.startLeScan(BLECallback); bluetoothAdapter.stopLeScan(BLECallback); Intent intent = new Intent(); intent.putExtra("macAddress", asset.MAC_address); intent.setAction(EVENT_NEW_ASSET); Intent intent = new Intent(); intent.putExtra("macAddress", asset.MAC_address); intent.setAction(EVENT_LOST_ASSET);
String action = intent.getAction(); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); btArray = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, android.R.id.text1); btArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); uuids[0] = UUID.fromString(uuid1); uuids[1] = UUID.fromString(uuid2); Toast.makeText(this, "Device Does not Support Bluetooth", Toast.LENGTH_LONG).show(); else if (!myBt.isEnabled()) { Set<BluetoothDevice> pairedDevices = myBt.getBondedDevices(); myBt.startDiscovery(); String[] vals = str.split("\n"); Log.e(TAG,"mac: "+vals[1]); BluetoothDevice dev = myBt.getRemoteDevice(vals[1]); mConnThread = new ConnectThread(dev); mConnThread.run(); myBt.cancelDiscovery(); Log.e(TAG,"stopping discovery");
OutputStream mBTOutputStream = null; static final UUID UUID_RFCOMM_GENERIC = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); mBTDevice = mBTAdapter.getRemoteDevice(mPeerMAC);
@Override public void run() { // always return a remote device BluetoothDevice remoteDevice = mBluetoothAdapter.getRemoteDevice(mac); mBluetoothAdapter.cancelDiscovery(); mCurrStatus = STATUS.FREE; try { Log.d(TAG, "prepare to connect: " + remoteDevice.getAddress() + " " + remoteDevice.getName()); // BluetoothSocket socket = remoteDevice.createRfcommSocketToServiceRecord(UUID.fromString(STR_UUID)); // BluetoothSocket socket = (BluetoothSocket) remoteDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class}).invoke(remoteDevice,1); mSocket = remoteDevice.createInsecureRfcommSocketToServiceRecord(UUID.fromString(Constants.STR_UUID)); // if(!socket.isConnected()) mSocket.connect(); mInputStream = mSocket.getInputStream(); mOutputStream = mSocket.getOutputStream(); mCurrStatus = STATUS.CONNECTED; } catch (Exception e) { if (listener != null) listener.onError(e); try { mInputStream.close(); mOutputStream.close(); } catch (IOException closeException) { closeException.printStackTrace(); } mCurrStatus = STATUS.FREE; } } }
synchronized private static void zebraPrint() throws IOException { BluetoothAdapter blueTooth = BluetoothAdapter.getDefaultAdapter(); blueTooth.cancelDiscovery(); UUID SERIAL_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); if (!blueTooth.isEnabled()) blueTooth.enable(); BluetoothDevice blueDevice = blueTooth.getRemoteDevice(printerMac); BluetoothSocket bSocket = blueDevice.createInsecureRfcommSocketToServiceRecord(SERIAL_UUID); if (!bSocket.isConnected()) bSocket.connect(); OutputStream out = bSocket.getOutputStream(); String data = "Your cpcl data"; out.write(text.getBytes()); out.flush(); bSocket.close(); }
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(macAddress); if (mState == STATE_CONNECTING) { if (mConnectThread != null) { mBluetoothAdapter.cancelDiscovery(); mConnectedThread = null; mBluetoothAdapter.cancelDiscovery(); return super.stopService(name); BluetoothSocket tmp = null; try { tmp = device.createRfcommSocketToServiceRecord(UUID.fromString(SPP_UUID)); } catch (IOException e) { e.printStackTrace(); public void run() { setName("ConnectThread"); mBluetoothAdapter.cancelDiscovery(); try { mmSocket.connect();
public ConnectThread(BluetoothDevice device, MainActivity ac) { // Use a temporary object that is later assigned to mmSocket, // because mmSocket is final Log.i("ConnectThread", "Starting connectThread"); this.ac=ac; BluetoothSocket tmp = null; mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // Get a BluetoothSocket to connect with the given BluetoothDevice try { // MY_UUID is the app's UUID string, also used by the server code UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); tmp = device.createRfcommSocketToServiceRecord(MY_UUID); } catch (IOException ignored) { Log.e("ConnectThread", "Error on getting the device"); } mmSocket = tmp; }
public void connect(Intent data) { String address = data.getExtras().getString(BluetoothState.EXTRA_DEVICE_ADDRESS); BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); mChatService.connect(device); }
@Override protected void onStart() { super.onStart(); final Intent intent = getIntent(); if (!isDeviceConnected() && intent.hasExtra(FeaturesActivity.EXTRA_ADDRESS)) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); final BluetoothDevice device = bluetoothAdapter.getRemoteDevice(getIntent().getByteArrayExtra(FeaturesActivity.EXTRA_ADDRESS)); onDeviceSelected(device, device.getName()); intent.removeExtra(FeaturesActivity.EXTRA_APP); intent.removeExtra(FeaturesActivity.EXTRA_ADDRESS); } }
private String resolveHWAddress(String hwaddress) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { for (BluetoothDevice btDevice : bluetoothAdapter.getBondedDevices()) { if (btDevice.getAddress().equals(hwaddress)) { return btDevice.getName(); } } } return null; }
@SuppressLint("DefaultLocale") public static void onBlueTooth(String action) { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter .getDefaultAdapter(); if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("on")) { if (!mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.enable(); } } if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("off")) { if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable(); } } }