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();
        }
  • 相关阅读:
    Object的原型拷贝-create、assign、getPrototypeOf 方法的结合
    配intelliJ IDEA 过程
    浅谈HTTP中Get与Post的区别
    apply、call、bind区别、用法
    引用类型与原始类型的区别
    html5标签集结1
    指针作为参数传递
    指针与指针变量
    函数模板
    内置函数
  • 原文地址:https://www.cnblogs.com/liuzhipenglove/p/7080164.html
Copyright © 2011-2022 走看看