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:com.netlinks.healthbracelet.service.HeartRateService.java
/** * Bluetooth Configuration/*w ww .ja v a2s.co m*/ * 1- Establishing the connection with the bracelet * 2- Create the socket */ public void BluetoothConfig() { final String address = "04:1B:BA:97:1A:33"; //Health Bracelet MAC address // If the adapter is null, then Bluetooth is not supported if (mAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); stopSelf(); return; } else { if (mAdapter.isEnabled()) { Log.d(TAG, "...Bluetooth is ON..."); } else { Log.d(TAG, "...Bluetooth is OFF..."); //TODO Requesting to open bluetooth (in a proper way) Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); enableBtIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //int REQUEST_ENABLE_BT = 404; getApplication().startActivity(enableBtIntent); } } Log.d(TAG, "...trying to connect..."); if (!BluetoothAdapter.checkBluetoothAddress(address)) { Log.d(TAG, "Fatal Error : Incorrect MAC-address"); } else { // Set up a pointer to the remote node using it's address. final BluetoothDevice device = mAdapter.getRemoteDevice(address); if (mState != STATE_CONNECTED) { this.connect(device); } } }
From source file:com.example.android.bluetoothchat.BluetoothFragment.java
@Override public void onStart() { super.onStart(); // If BT is not on, request that it be enabled. // setupChat() will then be called during onActivityResult if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the chat session } else if (mChatService == null) { setupChat();/*from w w w . j a v a2 s .c om*/ } }
From source file:com.pendragon.blueconnect.BluetoothChat.java
@Override public void onStart() { super.onStart(); if (D)//from w w w . jav a2 s . c o m Log.e(TAG, "++ ON START ++"); // Pedimos activar BT si no est activo // Si ya estaba activo, lanzamos el chat if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } else { if (mChatService == null) setupChat(); } }
From source file:com.example.android.bluetoothlegatt.ui.DeviceScanActivity.java
@Override protected void onResume() { super.onResume(); // Ensures Bluetooth is enabled on the device. If Bluetooth is not currently enabled, // fire an intent to display a dialog asking the user to grant permission to enable it. if (!mBluetoothAdapter.isEnabled()) { if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); }/* w ww . j a v a2 s . c om*/ } // Initializes list view adapter. mLeDeviceListAdapter = new LeDeviceListAdapter(); setListAdapter(mLeDeviceListAdapter); int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION); if (permissionCheck == 0) { scanLeDevice(true); } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, PERMISSIONS_COARSE_LOCATION); } }
From source file:com.example.android.bluetoothlegatt.DeviceScanActivity.java
@Override protected void onResume() { super.onResume(); // Ensures Bluetooth is enabled on the device. If Bluetooth is not currently enabled, // fire an intent to display a dialog asking the user to grant permission to enable it. if (!mBluetoothAdapter.isEnabled()) { if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); }//from ww w . ja va 2 s. co m } // Initializes list view adapter. mLeDeviceListAdapter = new LeDeviceListAdapter(); setListAdapter(mLeDeviceListAdapter); scanLeDevice(true); }
From source file:com.sdingba.su.lanya.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mBtAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBtAdapter == null) { // Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); Toast.makeText(this, " Bluetooth is not available------Bluetooth ??", Toast.LENGTH_LONG) .show();/*from ww w .j a v a 2 s. c om*/ finish(); return; } // showMessage("??"); messageListView = (ListView) findViewById(R.id.listMessage); listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail); messageListView.setAdapter(listAdapter); messageListView.setDivider(null); btnConnectDisconnect = (Button) findViewById(R.id.btn_select); btnSend = (Button) findViewById(R.id.sendButton); edtMessage = (EditText) findViewById(R.id.sendText); service_init(); // Handler Disconnect & Connect button btnConnectDisconnect.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!mBtAdapter.isEnabled()) { // mBtAdapter.isEnabled() == null ?? // // showMessage("mBtAdapter.isEnabled() = "+mBtAdapter.isEnabled()); //mBtAdapter.isEnabled()::::Return true if Bluetooth is currently enabled and ready for use. //Equivalent to: getBluetoothState() == STATE_ON Log.i(TAG, "onClick - BT not enabled yet"); Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } else { //TODO BUG //// TODO: 16-6-5 ??? ? // Connect ?? listView showMessage(" ??" + mState + " " + " 21 = UART_PROFILE_DISCONNECTED ; 20 = connection"); if (btnConnectDisconnect.getText().equals("Connect")) { //Connect button pressed, open DeviceListActivity // class, with popup windows that scan for devices // showMessage(" =-=======-= "); Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class); startActivityForResult(newIntent, REQUEST_SELECT_DEVICE); } else { showMessage(" ******** "); //Disconnect button pressed if (mDevice != null) { mService.disconnect(); } } } } }); //// TODO: 16-6-13 ] ? ? //?? // Handler Send button btnSend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText editText = (EditText) findViewById(R.id.sendText); String message = editText.getText().toString(); byte[] value; try { //send data to service value = message.getBytes("UTF-8"); mService.writeRXCharacteristic(value); //Update the log with time stamp String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); listAdapter.add("[" + currentDateTimeString + "] TX: " + message); messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); edtMessage.setText(""); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); // Set initial UI state }
From source file:com.example.deer.boochat.chat_room.BluetoothChatFragment.java
@Override public void onStart() { super.onStart(); // If BT is not on, request that it be enabled. // setupChat() will then be called during onActivityResult if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the chat session }//from w w w .ja va 2s . com setupChat(); }
From source file:me.iasc.microduino.blueserial.DeviceScanActivity.java
@Override protected void onResume() { super.onResume(); // Ensures Bluetooth is enabled on the device. If Bluetooth is not currently enabled, // fire an intent to display a dialog asking the user to grant permission to enable it. if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); }//from w ww. j a v a2s.c om // Initializes list view adapter. mLeDeviceListAdapter = new LeDeviceListAdapter(); setListAdapter(mLeDeviceListAdapter); scanLeDevice(true); }
From source file:com.wordpress.bennthomsen.ble_uart_remote.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//from w w w . j a v a 2 s .co m mBtAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBtAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } btnConnectDisconnect = (Button) findViewById(R.id.btn_select); time_more = (Button) findViewById(R.id.button_time_more); time_less = (Button) findViewById(R.id.button_time_less); dough_qnt = (Button) findViewById(R.id.button_dough_qnt); options = (Button) findViewById(R.id.button_options); color = (Button) findViewById(R.id.button_color); init_stop = (Button) findViewById(R.id.button_init_stop); startRecipe = (Button) findViewById(R.id.startRecipesBookSelectionActivity); // dont allow the user click on these buttons if not connected and GATT service discovered. time_more.setEnabled(false); time_less.setEnabled(false); dough_qnt.setEnabled(false); options.setEnabled(false); color.setEnabled(false); init_stop.setEnabled(false); isConnected = false; service_init(); // Handler Disconnect & Connect button btnConnectDisconnect.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!mBtAdapter.isEnabled()) { Log.i(TAG, "onClick - BT not enabled yet"); Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } else { if (btnConnectDisconnect.getText().equals("Connect")) { //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class); startActivityForResult(newIntent, REQUEST_SELECT_DEVICE); } else { //Disconnect button pressed if (mDevice != null) { mService.disconnect(); } } } } }); //Handler startRecipe startRecipe.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent booksIntent = new Intent(MainActivity.this, SelectionListActivity.class); booksIntent.putExtra("file", "recipes_books"); booksIntent.putExtra("level", "books"); booksIntent.putExtra("list_title", "Livros de receitas"); booksIntent.putExtra("isConnected", isConnected); startActivityForResult(booksIntent, REQUEST_SELECT_RECIPE); } }); time_more.setOnTouchListener(this); time_less.setOnTouchListener(this); options.setOnTouchListener(this); dough_qnt.setOnTouchListener(this); color.setOnTouchListener(this); init_stop.setOnTouchListener(this); }
From source file:org.debian.paulliu.kajiradoubra.controller.KajiraDouBraController.java
@Override public void onStart() { super.onStart(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { // Device does not support Bluetooth Log.w(LOGTAG, "No Bluetooth Adapter"); return;//from w w w .ja va 2 s. c om } if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } }