android系統app開啟藍芽+設定可見性
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
獲取藍芽狀態:
int State = Settings.Global.getInt(mContext.getContentResolver(),Settings.Global.BLUETOOTH_ON,0);//0關閉藍芽
State = 0;藍芽關閉狀態
State = 1;藍芽開啟狀態