예제 #1
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          // When discovery finds a device
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            Short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);

            mNewDevicesArrayAdapter.add(
                device.getName() + "\n" + "RSSI = " + rssi + "\n" + device.getAddress());

            // log for test
            if (device.getName().equals("Zhenan")) {
              DataLogger dl =
                  new DataLogger(device.getName(), device.getAddress(), rssi.intValue());
            }
            // When discovery is finished, change the Activity title
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            setTitle(R.string.scan_finish);
            if (mNewDevicesArrayAdapter.getCount() == 0) {
              String noDevices = getResources().getText(R.string.none_found).toString();
              mNewDevicesArrayAdapter.add(noDevices);
            }
          }
        }
예제 #2
0
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          bluetoothImage.setBackgroundResource(R.drawable.discovering_animation);
          anim = (AnimationDrawable) bluetoothImage.getBackground();
          if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
            discoverBT.setText(R.string.cancel_discovery);
            enableBT.setEnabled(false);
            checkBT.setEnabled(false);
            anim.start();
            Toast.makeText(MainActivity.this, R.string.discovering, Toast.LENGTH_SHORT).show();
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            discoverBT.setText(R.string.discover_devices);
            enableBT.setEnabled(true);
            checkBT.setEnabled(true);
            anim.stop();
            bluetoothImage.setBackground(getResources().getDrawable((R.drawable.btooth_on)));
            Toast.makeText(MainActivity.this, R.string.discovery_finished, Toast.LENGTH_SHORT)
                .show();
          } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device =
                (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            if (!tmpBtChecker.contains(device)) {
              tmpBtChecker.add(device);
              discoveredDevicesArList.add(device.getName() + "\n" + device.getAddress());
              adapterForDiscoveredDevices.notifyDataSetChanged();
            }
          }
        }
예제 #3
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          // When discovery finds a device
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            // If it's already paired, skip it, because it's been listed
            // already
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());

              // if (lastAdress.compareTo(device.getAddress())==0)
              // {
              setAndReturn(device.getAddress());
              // }
            }
            // When discovery is finished, change the Activity title
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            setTitle(R.string.select_device);
            if (mNewDevicesArrayAdapter.getCount() == 0) {
              String noDevices = getResources().getText(R.string.none_found).toString();
              mNewDevicesArrayAdapter.add(noDevices);
            }
          }
        }
예제 #4
0
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          // When discovery finds a device
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            // If it's already paired, skip it, because it's been listed already
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              String strNoFound = getIntent().getStringExtra("no_devices_found");
              if (strNoFound == null) strNoFound = "No devices found";

              if (mPairedDevicesArrayAdapter.getItem(0).equals(strNoFound)) {
                mPairedDevicesArrayAdapter.remove(strNoFound);
              }
              mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
            }

            // When discovery is finished, change the Activity title
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            String strSelectDevice = getIntent().getStringExtra("select_device");
            if (strSelectDevice == null) strSelectDevice = "Select a device to connect";
            setTitle(strSelectDevice);
          }
        }
예제 #5
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          Log.d(TAG, "进入广播:" + action.toString());

          // 发现设备
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            Log.d(TAG, "发现设备");
            devices.add(device.getName() + "\n" + device.getAddress());
            Log.d(TAG, "devices:" + device.getName() + "[" + device.getAddress() + "]");

            // 添加非配对设备
            if (isLock(device)) {
              String address = device.getAddress();

              devices.add(device.getName() + "\n" + device.getAddress());
              Log.d(TAG, "devices" + devices);
              deviceList.add(device);
              Log.d(TAG, "deviceList" + deviceList);
              Log.d(TAG, "address" + address);
              device1 = adapter.getRemoteDevice(address);
              Log.d(TAG, "device1:" + device1);
              blueclient.nativeInit(device);
            }
          }
        }
예제 #6
0
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          // ada device baru
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // ambil objek BluetoothDevice dari Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            arrayPairedDevices.add(device);
            // tulis nama dan MAC address ke ListView
            adapter.add("Baru:" + device.getName() + "\n" + device.getAddress());
            // refresh listview, JANGAN LUPA!!
            adapter.notifyDataSetChanged();
          } else
          // mulai proses discovery, untuk debug saja, memastikan proses dimulai
          if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
            Toast toast =
                Toast.makeText(
                    getApplicationContext(), "Mulai proses discovery", Toast.LENGTH_LONG);
            toast.show();
          } else
          // mulai proses discovery, untuk debug saja, memastikan proses dimulai
          if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            Toast toast =
                Toast.makeText(
                    getApplicationContext(), "Proses discovery selesai", Toast.LENGTH_LONG);
            toast.show();
          }
        }
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          Log.d(TAG, "广播接收者运行..." + action);

          // 查找到设备action
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // 得到蓝牙设备
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            // 如果是已配对的则略过,已得到显示,其余的在添加到列表中进行显示
            Log.d(TAG, device.toString());
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              mNewDevicesAdapter.add(device);
              tv_new_devices.setVisibility(View.VISIBLE);
              //                    newDevices.add(device);
            }
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            swiperefresh.setRefreshing(false);
            //                btn_sann.setVisibility(View.VISIBLE);
            if (mNewDevicesAdapter.getCount() == 0) {
              setTitle("没有找到新设备");
              Toast.makeText(DeviceListActivity.this, "没有发现新设备!", Toast.LENGTH_SHORT).show();
            } else {
              setTitle(getString(R.string.chose_to_connect));
              tv_new_devices.setVisibility(View.VISIBLE);
            }
          }
        }
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          // 查找到设备action
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // 得到蓝牙设备
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            // 如果是已配对的则略过,已得到显示,其余的在添加到列表中进行显示
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
            } else { // 添加到已配对设备列表
              mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
              // mPairedDevicesArrayAdapter.add(mBtAdapter.getRemoteDevice(device.getAddress()).getName() + "\n" + device.getAddress());
            }
            // 搜索完成action
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            setTitle(getResources().getString(R.string.select));
            if (mNewDevicesArrayAdapter.getCount() == 0) {
              String noDevices = getResources().getString(R.string.nonewdevice);
              mNewDevicesArrayAdapter.add(noDevices);
            }
          }
        }
예제 #9
0
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            Toast.makeText(
                    getApplicationContext(), "Device found" + device.getName(), Toast.LENGTH_SHORT)
                .show(); // Device found
            if (device.getName().equals("SM-T325")) {
              visits++;
              ((TextView) findViewById(R.id.textView))
                  .setText("Number of visits this month: " + MainActivity.visits + " times");
            }
          } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
            Toast.makeText(getApplicationContext(), "Action connected", Toast.LENGTH_SHORT)
                .show(); // Device is now connected
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            Toast.makeText(getApplicationContext(), "Discovery finished", Toast.LENGTH_SHORT)
                .show(); // Done searching
          } else if (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) {
            Toast.makeText(getApplicationContext(), "Disconnect Requested", Toast.LENGTH_SHORT)
                .show(); // Device is about to disconnect
          } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
            Toast.makeText(getApplicationContext(), "Disconnected", Toast.LENGTH_SHORT)
                .show(); // Device has disconnected
          }
        }
예제 #10
0
        @Override
        public void onReceive(Context context, Intent intent) {
          Log.e("STEGANOS", "Inside the onreceive method");
          String action = intent.getAction();
          // When discovery finds a device
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    Toast.makeText(getBaseContext(), "Device found", Toast.LENGTH_SHORT).show();
                  }
                });
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device =
                (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            // If it's already paired, skip it, because it's been listed alreadsy
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
            }

            // When discovery is finished, change the Activity title
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    Toast.makeText(getBaseContext(), "Discovery Finished!", Toast.LENGTH_SHORT)
                        .show();
                  }
                });
          }
        }
예제 #11
0
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   if (BluetoothDevice.ACTION_FOUND.equals(action)) {
     BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     String name = device.getName();
     Log.d("Bluetooth Device:", name);
   }
 }
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   if (BluetoothDevice.ACTION_FOUND.equals(action)) {
     BluetoothDevice bluetoothDevice =
         intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     adapter.add(bluetoothDevice.getName() + "\n" + bluetoothDevice.getAddress());
   }
 }
예제 #13
0
 @Override
 public void onReceive(Context context, Intent intent) {
   if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
     mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     Toast.makeText(MainActivity.this, mDevice.getName(), Toast.LENGTH_SHORT).show();
     mBluetoothAdapter.cancelDiscovery();
     Toast.makeText(MainActivity.this, "準備完了", Toast.LENGTH_SHORT).show();
   }
 }
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   // When discovery finds a device
   if (BluetoothDevice.ACTION_FOUND.equals(action)) {
     // Get the BluetoothDevice object from the Intent
     BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     // Add the name and address to an array adapter to show in a ListView
     mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
   }
 }
예제 #15
0
 /*
    This is a callback function that is called when device discovery finds a new device.
 */
 @Override
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   if (BluetoothDevice.ACTION_FOUND.equals(action)) {
     BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     addDiscoveredList(device);
     // Toast.makeText(context, "Discovered device : " + device.getName() + "--" +
     // device.getAddress(), Toast.LENGTH_SHORT).show();
   }
 }
예제 #16
0
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   // When discovery finds a device
   if (BluetoothDevice.ACTION_FOUND.equals(action)) {
     // Get the BluetoothDevice object from the Intent
     BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     // add the name and the MAC address of the object to the arrayAdapter
     BTArrayAdapter.add(device.getName() + "\n" + device.getAddress());
     BTArrayAdapter.notifyDataSetChanged();
   }
 }
예제 #17
0
        @Override
        public void onReceive(Context context, Intent intent) {
          if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
            BluetoothDevice found =
                (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            // Filter duplicates
            for (BluetoothDevice d : m_foundDevices)
              if (d.getAddress().equals(found.getAddress())) return;

            m_foundDevices.add(found);
          }
        }
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice bluetoothDevice =
                intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            if (bluetoothDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
              _bluetoothDevicesAdapter.addItem(bluetoothDevice);
              _bluetoothDevicesAdapter.notifyDataSetChanged();
            }
          }
        }
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          String name = "";
          // When discovery finds a device
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            if (name == null) {
              mArrayAdapter.add(device.getAddress());
            } else {
              mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
            }
          }
        }
        // 検出されたデバイスからのブロードキャストを受ける
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          String dName = null;
          BluetoothDevice foundDevice;
          if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
            Log.d("BP", "スキャン開始");
          }
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // デバイスが検出された
            Log.d("BP", "デバイス検出");
            foundDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            foundDeviceList.add(foundDevice);
            if ((dName = foundDevice.getName()) != null) {
              Log.d("BP", "デバイス: " + dName);
              BtClientRead thread = new BtClientRead(mContext, foundDevice, mBtAdapter);
              thread.start();
              Log.d("BP", "BtClientThreadスタート");
              // ArrayList<String> dataList = null;
              data = "";
              try {
                data = thread.getValue();
                thread.cancel();
                Log.d("BP", "BtClientThreadストップ");
              } catch (InterruptedException e) {
                e.printStackTrace();
              }
              linear_layout.removeView(waitText);
              linear_layout.removeView(progressBar);
              String[] dataArray = data.split("&");
              String name = dataArray[3];
              nonPairedDeviceAdapter.add("" + name);
              Log.d("BP", "デバイス検出終了");

              // if(foundDevice.getBondState() != BluetoothDevice.BOND_BONDED){
              // 接続したことのないデバイスのみアダプタに詰める
              // nonPairedDeviceAdapter.add(dName + "\n" + foundDevice.getAddress());
              // Log.d("ACTION_FOUND", dName);
              // }
            }
            // nonpairedList.setAdapter(nonPairedDeviceAdapter);
          }

          if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            Log.d("BP", "スキャン終了");
          }
        }
예제 #21
0
  @Override
  public void onReceive(Context context, Intent intent) {

    if (bluetoothAdapter == null) {
      return;
    }

    String action = intent.getAction();
    // When discovery finds a device

    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

      if (device == null) {
        return;
      }

      String name = device.getName();
      if (name == null) {
        return;
      }

      if (DEVICE_NAME_LIST.contains(name)) {
        deviceNames.put(device.getName(), device.getAddress());
        devices.put(device.getName(), device);

        cancelDiscovery();

        try {
          byte[] pin = ByteBuffer.allocate(4).putInt(1234).array();
          Method m = device.getClass().getMethod("setPin", byte[].class);
          m.invoke(device, pin);

          device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
          device.getClass().getMethod("cancelPairingUserInput", boolean.class).invoke(device);
        } catch (Exception e) {
          e.printStackTrace();
        }

        sendCurrentStateMessage(
            BluetoothManagerState.DEVICE_FOUND,
            new DeviceDTO(device.getName(), device.getAddress()));
      }
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
      bluetoothAdapter.cancelDiscovery();
    }
  }
예제 #22
0
        @Override
        public void onReceive(Context context, Intent intent) {

          String action = intent.getAction();

          // 如果找到远程设备
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {

            String remoteDeviceName = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);

            BluetoothDevice remoteDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            // 找到设备后将其添加到列表显示,包括设备名和设备地址
            deviceList.add(new DeviceList(remoteDevice, remoteDeviceName));
          } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
            tvinfo.setText(String.format("与%s建立连接失败,请重新连接", deviceName));
          }
        }
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
            }
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            setTitle(R.string.select_device);
            if (mNewDevicesArrayAdapter.getCount() == 0) {
              String noDevices = getResources().getText(R.string.none_found).toString();
              mNewDevicesArrayAdapter.add(noDevices);
            }
          }
        }
예제 #24
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            if ((device.getBondState() != BluetoothDevice.BOND_BONDED)
                && (device.getBluetoothClass().getDeviceClass()
                    == BluetoothClass.Device.TOY_ROBOT)) {
              mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
              findViewById(R.id.title_new_devices).setVisibility(View.VISIBLE);
              findViewById(R.id.no_devices).setVisibility(View.GONE);
            }
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            setTitle("Select device");
            findViewById(R.id.button_scan).setVisibility(View.VISIBLE);
          }
        }
예제 #25
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          // When discovery finds a device
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            // If it's already paired, skip it, because it's been listed already
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              String dev_name = device.getName();
              if (dev_name.substring(0, c_id_length) == cluster_id) {
                discovered_devices.add(device.getName());
              }
            }
            // When discovery is finished, change the Activity title
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            outData();
          }
        }
예제 #26
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          // When discovery finds a device
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            // Log.d("bbtt", "device:"+device.getName()+":"+device.getAddress());

            // If it's already paired, skip it, because it's been listed already
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              if (devices != null) {
                // devices.add(device);
                addDevice(device);
              }
              if (DEBUG) Log.d("bbtt", "device2:" + device.getName() + ":" + device.getAddress());
            }

            // When discovery is finished, change the Activity title
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            // if(devices!=null){
            // Log.d("testthread", "scanning devices finish ...."+devices.size());
            // }
            stopTimeoutTimer(); // 停掉计时
            new Thread() {
              public void run() {
                try {
                  if (!BaseConnectOBDService.addingCar) {
                    // Log.d("testthread", "cricleConnect...");
                    cricleConnetOBD(devices);
                  }
                  connetState = 1; // 查找结束
                } catch (InterruptedException e) {
                  connetState = 1; // 查找结束
                  e.printStackTrace();
                }
              }
            }.start();
          }
        }
예제 #27
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          // When discovery finds a device
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            // If it's already paired, skip it, because it's been listed already
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
            }
            // When discovery is finished, change the Activity title
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {

            if (mNewDevicesArrayAdapter.size() == 0) {
              String noDevices = getResources().getText(R.string.none_found).toString();
              mNewDevicesArrayAdapter.add(noDevices);
            }
          }
        }
예제 #28
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // ... //Device found
          } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
            // Device is now connected
            PrintHelper.SetIsConnected(true);
            AppGlobals.printerTestDialogFragment.SetPrinterStatus();
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            // Done searching
          } else if (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) {
            // Device is about to disconnect
          } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
            // Device has disconnected
            PrintHelper.SetIsConnected(false);
            AppGlobals.printerTestDialogFragment.SetPrinterStatus();
          }
        }
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   Log.d("Блютуз", "Чет пришло на ресивер: " + intent.getAction());
   if (BluetoothDevice.ACTION_FOUND.equals(action)) {
     BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     Log.d("Блютуз", "Я тебя нашел, " + device.getName() + "!!!");
     if (device.getName().contains(BluetoothInterface.PREFIX))
       onNewServerFound(device.getName().substring(BluetoothInterface.PREFIX.length()));
   }
   if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
     onDiscoveryFinish();
   }
   if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
     if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0) == BluetoothAdapter.STATE_ON) {
       onAdapterOn();
     } else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)
         == BluetoothAdapter.STATE_OFF) {
       onAdapterOff();
     }
   }
 }
예제 #30
0
        @Override
        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 {
              // device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device,
              // true);
              // device.getClass().getMethod("cancelPairingUserInput",
              // boolean.class).invoke(device);
            } catch (Exception e) {
              Log.i("Log", "Inside the exception: ");
              e.printStackTrace();
            }

            if (arrayListBluetoothDevices.size()
                < 1) // this checks if the size of bluetooth device is 0,then add the
            { // device to the arraylist.
              detectedAdapter.add(device.getName() + "\n" + device.getAddress());
              arrayListBluetoothDevices.add(device);
              detectedAdapter.notifyDataSetChanged();
            } else {
              boolean flag =
                  true; // flag to indicate that particular device is already in the arlist or not
              for (int i = 0; i < arrayListBluetoothDevices.size(); i++) {
                if (device.getAddress().equals(arrayListBluetoothDevices.get(i).getAddress())) {
                  flag = false;
                }
              }
              if (flag == true) {
                detectedAdapter.add(device.getName() + "\n" + device.getAddress());
                arrayListBluetoothDevices.add(device);
                detectedAdapter.notifyDataSetChanged();
              }
            }
          }
        }