Code example for BluetoothAdapter

Methods: enable, getScanMode, isEnabled

0
	} 
 
	private void ensureDiscoverable() { 
		if (D)
			Log.d(TAG, "Inside method: ensureDiscoverable");
		if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
			Intent discoverableIntent = new Intent(
					BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
			discoverableIntent.putExtra(
					BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
			discoverableIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			startActivity(discoverableIntent);
		} 
	} 
 
	@Override 
	public IBinder onBind(Intent intent) {
		return mMessenger.getBinder();
	} 
 
	@Override 
	public void onCreate() { 
		if (D)
			Log.d(TAG, "Inside method: onCreate");
		super.onCreate(); 
 
		// is the bluetooth turned on? 
		mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
		// turn bt on if it not turned on 
		if (!mBluetoothAdapter.isEnabled())
			mBluetoothAdapter.enable();
 
		// define filter for broadcast 
		intFilter = new IntentFilter();
		intFilter.addAction(BluetoothDevice.ACTION_FOUND);
		intFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);