public class MainActivity extends Activity{        int REQUEST_ENABLE_BT = 1;        ……        @Override        protected void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentView(R.layout.activity_main);            initBluetooth();        }        /*判断手机是否已经打开蓝牙,如果没有,询问用户是否要打开*/       @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)       public void initBluetooth() {           //如果手机硬件不支持蓝牙,弹出提示消息           if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {               Toast.makeText(this, "Not support BLE", Toast.LENGTH_SHORT).show();               // finish();           }           //获取手机本地的蓝牙适配器           final BluetoothManager bluetoothManager =                   (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);           BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();           //如果蓝牙没打开,询问用户是否要打开蓝牙           if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {               Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);               startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);           }       }}
  BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); //获取已配对的蓝牙设备 Set devices = adapter.getBondedDevices(); for (BluetoothDevice device : devices) {     System.out.println("已配对的设备名称:" + device.getName() + "uuids" + device.getUuids()); }

更多相关文章

  1. Android(安卓)打开Activity后,不显示键盘
  2. 「Android」使用SAF打开指定目录
  3. Android(安卓)蓝牙开发浅析
  4. 用Android代码实现自动打开USB调试
  5. Android获取打开各种文件Intent汇总
  6. Android(三)Android(安卓)SDK无法更新解决方式
  7. Android(安卓)Ble
  8. 启动模式详解
  9. 打开Android(安卓)Studio报错"required plugin “Android(安卓)S

随机推荐

  1. Android(安卓)- DownloadManager的使用
  2. Android(安卓)camera系统开发之IPC (五)
  3. Android通知栏技巧
  4. Android(安卓)NDK几点回调方式(device id
  5. android 控制手机音量的大小 切换声音的
  6. Android(安卓)file 文件重命名删除详解
  7. Android(安卓)ORM-GreenDao学习之一基础
  8. Android(安卓)N之hasSystemFeature
  9. 实用技巧 - 收藏集 - 掘金
  10. ANDROID ANT打包