List of usage examples for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE
String ACTION_REQUEST_ENABLE
To view the source code for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE.
Click Source Link
From source file:Main.java
public static void enableRequest(Activity activity, int requestCode) { Intent btOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(btOn, requestCode); }
From source file:Main.java
public static void enableBluetooth(Activity activity, int requestCode) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(intent, requestCode); }
From source file:Main.java
public static void startRequestEnableBluetoothActivityForResult(Activity activity) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(intent, REQUEST_ENABLE_BT); }
From source file:Main.java
public static boolean initializeBluetooth(Activity activity) { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { // Device does not support Bluetooth return false; }/* www .j a v a 2 s .com*/ int REQUEST_ENABLE_BT = 1; if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } return false; }
From source file:Main.java
/** * Enable the bluetooth adapter./*from ww w .j a v a2 s . c o m*/ */ public static void bluetoothEnable(Activity activity, boolean discoverable, int reqCode) { if (discoverable) { Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0); activity.startActivityForResult(discoverableIntent, reqCode); } else { Intent bluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(bluetoothIntent, reqCode); } }
From source file:Main.java
/** * Enables bluetooth function.<br /> * the Activity may implement the `onActivityResult` method with the request code `REQUEST_CODE_BLUETOOTH_ENABLE`. * * @param activity the activity//from w w w.ja v a 2 s. c o m */ public static void enableBluetooth(@NonNull Activity activity) { activity.startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_BLUETOOTH_ENABLE); }
From source file:Main.java
public static void checkPhoneSettings(Activity activity) { //Check if device supports bluetooth: if (mBluetoothAdapter == null) { //!TODO//from w w w.j a va 2s . com } else { Log.v("", "Bluetooth is supported"); //Check if bluetooth is enabled. If not, request the user to enable it. if (!mBluetoothAdapter.isEnabled()) { Log.v("", "Bluetooth is not turned on"); Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } else { deviceMAC = getMACAddress(); } } }
From source file:Main.java
/** * Enable bluetooth and get the adapter object * @return A BluetoothAdapter instance/* w w w. jav a2 s . co m*/ */ public static BluetoothAdapter getLeAdapter(Activity _this) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothLeManager = (BluetoothManager) _this .getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter bluetoothLeAdapter = bluetoothLeManager.getAdapter(); // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to mEnableCharacteristic Bluetooth. // TODO / FIXME currently this bugs if the user doesn't have BT enabled, // TODO / FIXME since it just returns null and doesn't check the result later. if (bluetoothLeAdapter == null || !bluetoothLeAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); _this.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); return null; } else { return bluetoothLeAdapter; } }
From source file:Main.java
public static Pair<BluetoothManager, BluetoothAdapter> checkBT(final Activity activity) { // Use this check to determine whether BLE is supported on the device. Then // you can selectively disable BLE-related features. if (!btleSupport(activity)) { return null; }//from w w w .j a va2 s. c o m final BluetoothManager bluetoothManager = (BluetoothManager) activity .getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); //On some devices this does not work try { bluetoothAdapter.getBluetoothLeScanner(); } catch (NoSuchMethodError e) { return null; } // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, 1); bluetoothAdapter = bluetoothManager.getAdapter(); } return new Pair<BluetoothManager, BluetoothAdapter>(bluetoothManager, bluetoothAdapter); }
From source file:org.deviceconnect.android.deviceplugin.host.activity.BluetoothManageActivity.java
@Override protected void onStart() { super.onStart(); mRequestParam = new Bundle(getIntent().getExtras()); if (MessageUtils.getAttribute(getIntent()).equals(ConnectionProfile.ATTRIBUTE_BLUETOOTH)) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); try {//from www . ja v a 2 s. c om startActivityForResult(enableIntent, 0); } catch (ActivityNotFoundException e) { BluetoothAdapter.getDefaultAdapter().enable(); } } else if (MessageUtils.getAttribute(getIntent()).equals(ConnectionProfile.ATTRIBUTE_BLE)) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); try { startActivityForResult(enableIntent, 0); } catch (ActivityNotFoundException e) { BluetoothAdapter.getDefaultAdapter().enable(); } } else { // finish if attribute is unknown finish(); } }