BluetoothAdapter blue = BluetoothAdapter.getDefaultAdapter();
这两个方法足矣满足你的需求(需要system权限):
blue.enable();
//需要加延时(打开蓝牙过程需要时间)
try{
Thread.sleep(1000);
}catch (Excetion e){
e.printStackTrace();
}
blue.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
blue.setDiscoverableTimeout(0);//0:蓝牙永久可见
**************************************************************************************************************************
操作数据库打开关闭蓝牙
# cd /data/data/com.android.providers.settings/databases
# sqlite3 settings.db
# .table
# select * from global;
打开/关闭蓝牙:String
BLUETOOTH_ON = "bluetooth_on";
Settings.Global.putInt(mContext.getContentResolver(),Settings.Global.BLUETOOTH_ON,1);//0关闭蓝牙
获取蓝牙状态:
int State = Settings.Global.getInt(mContext.getContentResolver(),Settings.Global.BLUETOOTH_ON,0);//0关闭蓝牙
State = 0;蓝牙关闭状态
State = 1;蓝牙打开状态