zoukankan      html  css  js  c++  java
  • Android之BroadcastReceiver

    [代码来源:GOOGLE原生示例BluetoothChat]

    [代码功能:实现对安卓蓝牙设备检测到的事件广播的处理]

    [代码如下]

      // The BroadcastReceiver that listens for discovered devices and
      // changes the title when discovery is finished
      private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @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() + "
    " + 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);
            }
          }
        }
      };
  • 相关阅读:
    Javascript中this关键字详解
    Chrome 中的 JavaScript 断点设置和调试技巧
    将Sublime Text3添加到右键菜单中
    sublime text 3如何安装插件和设置字号
    sublime text 侧边栏样式修改
    JS中关于clientWidth offsetWidth scrollWidth 等的含义
    scrollWidth,clientWidth,offsetWidth的区别
    JS中apply和call的用法
    JS中的call()和apply()方法
    JAVA-初步认识-第四章-函数-Demo练习
  • 原文地址:https://www.cnblogs.com/jayhust/p/4173508.html
Copyright © 2011-2022 走看看