[automator学习篇]android 接口-- bluetooth

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

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

在编译服务器上的目录:  /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();
    }

 

posted @ 2017-06-26 13:48  liuzhipenglove  阅读(229)  评论(0编辑  收藏  举报