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();
        }
  • 相关阅读:
    向量、矩阵常用范数
    关于HP M451网络连接的资料
    pyqt程序最小化到系统托盘(未测试)
    博客园美化大集合2020最新!不用担心失效问题!
    添加QQ聊天
    关于加密
    python抓取谷歌学术关键词下文章题目
    如何确定网站可否可爬取
    灵狐浏览器
    利用beautifulsoup进行对标签的二次查找-以打印网易云歌单内容为例
  • 原文地址:https://www.cnblogs.com/liuzhipenglove/p/7080164.html
Copyright © 2011-2022 走看看