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();
        }
  • 相关阅读:
    php安装扩展的几种方法
    navicat连接linux系统中mysql-错误:10038
    linux下报错bash: service: command not found
    linux配置防火墙和重启防火墙
    linux 环境安装
    匿名函数
    workman的学习总结
    xampp/apache启动失败解决方法
    Linux 查看IP
    慢查询日志
  • 原文地址:https://www.cnblogs.com/liuzhipenglove/p/7080164.html
Copyright © 2011-2022 走看看