zoukankan      html  css  js  c++  java
  • [Android Pro] 监听Blutooth打开广播

       <uses-permission android:name="android.permission.BLUETOOTH"/>
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
            IntentFilter filter = new IntentFilter();
            filter.setPriority(2147483647);
            filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
            registerReceiver(mBluetoothReceiver, filter);
    
    private BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent != null) {
                    String action = intent.getAction();
                    if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                        int bluetoothState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
                        switch (bluetoothState) {
                            case BluetoothAdapter.STATE_OFF :
                                if (FeatureConfig.DEBUG_LOG) {
                                    Log.e("H3c", "bluetoothState STATE_OFF");
                                }
                                break;
                            case BluetoothAdapter.STATE_ON :
                                if (FeatureConfig.DEBUG_LOG) {
                                    Log.e("H3c", "bluetoothState STATE_ON ");
                                }
                                BluetoothAdapter mBluetoothAdapter = BluetoothAdapter
                  .getDefaultAdapter();
                    
    boolean result = false;
                     if (mBluetoothAdapter != null) {
                     result = mBluetoothAdapter.disable();
                     }
    break; } } } } };

    open bluetooth

     BluetoothAdapter mBluetoothAdapter = BluetoothAdapter
           .getDefaultAdapter();
     if (mBluetoothAdapter != null) {
           mBluetoothAdapter.enable();
     }
  • 相关阅读:
    提取文件唯一标识符
    U盘出现很多.exe的文件处理方案
    winform做的excel与数据库的导入导出
    php获取数据库结构
    根据手机屏幕的旋转,调整图片
    c#中base64编码解码
    遮罩层的实现
    opencv车流量统计算法
    winform创建快捷方式
    mysql存储过程中like用法
  • 原文地址:https://www.cnblogs.com/0616--ataozhijia/p/4831506.html
Copyright © 2011-2022 走看看