zoukankan      html  css  js  c++  java
  • [automator学习篇]android 接口-- bluetooth

    http://www.android-doc.com/guide/topics/connectivity/bluetooth.html

    本地下载的sdk 目录:     D:AndroidSdksourcesandroid-25androidluetooth,里面提供了很多接口,用来建立蓝牙;

    在编译服务器上的目录:  /home/liuzhipeng/workspace/AndroidN/android/frameworks/base/core/java/android/bluetooth

    1) 开启蓝牙

    http://blog.sina.com.cn/s/blog_537d61430101d4tw.html

    public class openAndCloseBluetooth {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    private String logTag = "bluetoothtest";

    @Test
    public void openBluetooth() throws Exception {
    if(mBluetoothAdapter == null){
    Log.i(logTag,"device not support bluetooth");
    return ;
    }
    if(!mBluetoothAdapter.isEnabled()){
    Log.i(logTag,"start bluetooth");
    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    Context context = InstrumentationRegistry.getContext();
    context.startActivity(enableBtIntent);
    Log.i(logTag,"start bluetooth success");

    }
    // mBluetoothAdapter.enable();
    }

    }

    这种是弹出对话框的

    另外一种是不打开对话框的:

        public void openBluetooth() throws Exception {
            if(mBluetoothAdapter == null){
                Log.i(logTag,"device not support bluetooth");
                return ;
            }
    //        if(!mBluetoothAdapter.isEnabled()){
    //            Log.i(logTag,"start bluetooth");
    //            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    //            Context context = InstrumentationRegistry.getContext();
    //            context.startActivity(enableBtIntent);
    //            Log.i(logTag,"start bluetooth success");
    //
    //        }
            mBluetoothAdapter.enable();
        }
  • 相关阅读:
    docker 容器
    web开发相关工具总结
    Linux] Git: push 出错的解决 master -> master (branch is currently checked out)
    MongoDB
    vs code 快捷键
    flutter 实现圆角头像的2种方法
    Flutter web环境变量搭建及开发
    使用VS Code调试Flutter(检查用户页面)
    Flutter走过的坑(持续更新)
    react link引入外部css样式的坑
  • 原文地址:https://www.cnblogs.com/liuzhipenglove/p/7080164.html
Copyright © 2011-2022 走看看