2

有沒有辦法強制藍牙?Android:強制藍牙

都讓我發現到目前爲止是這樣的(使用estimote SDK,其中我的工作):

// Check if device supports Bluetooth Low Energy. 
if (!beaconManager.hasBluetooth()) { 
    Toast.makeText(this, "Device does not have Bluetooth Low Energy", Toast.LENGTH_LONG).show(); 
    return; 
} 

// If Bluetooth is not enabled, let user enable it. 
if (!beaconManager.isBluetoothEnabled()) { 
    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); 
} 
else { 
    connectToBlueTooth(); 
} 

然後在onActivityResult

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == REQUEST_ENABLE_BT) { 
     if (resultCode == Activity.RESULT_OK) { 
      connectToBlueTooth(); 
     } 
     else { 
      Toast.makeText(this, "Bluetooth not enabled", Toast.LENGTH_LONG).show(); 
     } 
    } 
    super.onActivityResult(requestCode, resultCode, data); 
} 

但這要求給用戶,如果他想打開藍牙......但有沒有辦法打開它而不詢問用戶?

而且,如果無法做到這一點,我該如何在活動之外使用這種技術?

感謝

回答

4

嘗試BluetoothAdapter這樣的:

BluetoothAdapter.getDefaultAdapter().enable(); 
+0

光滑如絲!非常感謝你! – aveschini

+0

別提它.. – ExceedLimits