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:net.cherryzhang.sekuhara.BluetoothButtonAndChat.BluetoothChat.BluetoothChat.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.main, container, false); // 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 {//from w w w.j a v a2s . c o m if (mChatService == null) setupChat(rootView); } return rootView; }
From source file:com.mbientlab.metawear.app.ModuleActivity.java
@SuppressWarnings("unchecked") @Override//from w ww . j a va 2 s.com protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (!bluetoothManager.getAdapter().isEnabled()) { final Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } getApplicationContext().bindService(new Intent(this, MetaWearBleService.class), this, Context.BIND_AUTO_CREATE); if (savedInstanceState != null) { device = (BluetoothDevice) savedInstanceState.getParcelable(EXTRA_BLE_DEVICE); moduleFragment = (ModuleFragment) getSupportFragmentManager().getFragment(savedInstanceState, "mContent"); tapType = savedInstanceState.getInt(Extra.TAP_TYPE); tapAxis = savedInstanceState.getInt(Extra.TAP_AXIS); shakeAxis = savedInstanceState.getInt(Extra.SHAKE_AXIS); dataRange = savedInstanceState.getInt(Extra.DATA_RANGE); samplingRate = savedInstanceState.getInt(Extra.SAMPLING_RATE); ffMovement = savedInstanceState.getBoolean(Extra.FF_MOVEMENT); newFirmware = savedInstanceState.getBoolean(Extra.NEW_FIRMWARE); samplingConfigBytes = savedInstanceState.getByteArray(Extra.SAMPLING_CONFIG_BYTES); polledData = (ArrayList<byte[]>) savedInstanceState.getSerializable(Extra.POLLED_DATA); } }
From source file:com.cardiograph.view.BLEActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);// w ww . j ava 2s .co m mBtAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBtAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } 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()) { 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(BLEActivity.this, DeviceListActivity.class); startActivityForResult(newIntent, REQUEST_SELECT_DEVICE); } else { //Disconnect button pressed if (mDevice != null) { mService.disconnect(); } } } } }); // 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.wordpress.bennthomsen.bleuart.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*w w w . ja v a2s. co m*/ mBtAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBtAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } 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()) { 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 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:fr.bmartel.android.dotti.DottiActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dotti); // Use this check to determine whether BLE is supported on the device. Then // you can selectively disable BLE-related features. if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, "Bluetooth Smart is not supported on your device", Toast.LENGTH_SHORT).show(); finish();//from www . j av a2 s. c om } mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } final ProgressBar progress_bar = (ProgressBar) findViewById(R.id.scanningProgress); if (progress_bar != null) progress_bar.setEnabled(false); final Button button_stop_scanning = (Button) findViewById(R.id.stop_scanning_button); if (button_stop_scanning != null) button_stop_scanning.setEnabled(false); final TextView scanText = (TextView) findViewById(R.id.scanText); if (scanText != null) scanText.setText(""); registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter()); button_stop_scanning.setEnabled(false); final Button button_find_accessory = (Button) findViewById(R.id.scanning_button); button_stop_scanning.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentService != null && currentService.isScanning()) { currentService.stopScan(); if (progress_bar != null) { progress_bar.setEnabled(false); progress_bar.setVisibility(View.GONE); } if (scanText != null) scanText.setText(""); if (button_stop_scanning != null) button_stop_scanning.setEnabled(false); } } }); button_find_accessory.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { triggerNewScan(); } }); if (mBluetoothAdapter.isEnabled()) { Intent intent = new Intent(this, DottiBtService.class); // bind the service to current activity and create it if it didnt exist before startService(intent); bound = bindService(intent, mServiceConnection, BIND_AUTO_CREATE); } }
From source file:com.ahmedabdelmeged.bluetoothmc.ui.BluetoothDevices.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bluetooth_devices); initializeScreen();/*from w w w . j a va2 s . c o m*/ //check if the device has a bluetooth or not //and show Toast message if it does't have mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); //set the bluetooth adapter LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); deviceRecycler.setLayoutManager(linearLayoutManager); deviceRecycler.setHasFixedSize(true); bluetoothDevicesAdapter = new BluetoothDevicesAdapter(new ArrayList<String>(), this); deviceRecycler.setAdapter(bluetoothDevicesAdapter); if (mBluetoothAdapter == null) { Toast.makeText(this, R.string.does_not_have_bluetooth, Toast.LENGTH_LONG).show(); finish(); } else if (!mBluetoothAdapter.isEnabled()) { Intent enableIntentBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntentBluetooth, REQUEST_ENABLE_BT); } else if (mBluetoothAdapter.isEnabled()) { PairedDevicesList(); } setBroadCastReceiver(); //request location permission for bluetooth scanning for android API 23 and above ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_ENABLE_FINE_LOCATION); //press the button to start search new Devices searchForNewDevices.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchForNewDevices.setEnabled(false); searchProgressbar.setVisibility(View.VISIBLE); bluetoothDevicesAdapter.clear(); PairedDevicesList(); NewDevicesList(); } }); }
From source file:com.scytulip.nrfUARTbackrec.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.main);//from w w w . jav a2 s . c o m mBtAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBtAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } 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); btnDwnd = (Button) findViewById(R.id.dlButton); edtMessage = (EditText) findViewById(R.id.sendText); service_init(); mBackData = new BackRecData(getApplicationContext()); // 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 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(); } } }); // Handler Download Button btnDwnd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { mService.writeRXCharacteristic("T".getBytes("UTF-8")); } catch (Exception e) { Log.i(TAG, e.toString()); } } }); // Set initial UI state }
From source file:com.artur.softwareproject.BluetoothConnectionList.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bluetooth_connection); ListView bluetoothList;/*from w w w .j a v a 2 s.c o m*/ bluetoothList = (ListView) findViewById(R.id.bluetoothList); ListAdapter = new BluetoothConnectionListAdapter(this, bluetoothAddress, bluetoothName, bDevices); bluetoothList.setAdapter(ListAdapter); BluetoothManager bluetoothManager; bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); mHandler = new Handler(); File topLevelDir, jsonDir, objDir; //Creating the directory structure for the app. topLevelDir = new File(Environment.getExternalStorageDirectory() + "/ViSensor"); jsonDir = new File(Environment.getExternalStorageDirectory() + "/ViSensor/Json"); objDir = new File(Environment.getExternalStorageDirectory() + "/ViSensor/Obj"); if (!topLevelDir.exists()) { if (!topLevelDir.mkdir()) { Log.d(TAG, "Creating top level directory failed."); } if (!jsonDir.exists()) { if (!jsonDir.mkdir()) { Log.d(TAG, "Creating json directory failed."); } } if (!objDir.exists()) { if (!objDir.mkdir()) { Log.d(TAG, "Creating obj directory failed."); } } } else if (!jsonDir.exists()) { if (!jsonDir.mkdir()) { Log.d(TAG, "Creating json directory failed."); } if (!objDir.exists()) { if (!objDir.mkdir()) { Log.d(TAG, "Creating obj directory failed."); } } } else if (!objDir.exists()) { if (!objDir.mkdir()) { Log.d(TAG, "Creating obj directory failed."); } } if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); final int REQUEST_ENABLE_BT = 1; startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } int permissionCheckLocation = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION); int permissionCheckWrite = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (permissionCheckLocation != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 0); } if (permissionCheckWrite != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); } scanLeDevice(true); }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.fragments.SensorConfigFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true);/*from w w w . j ava2 s. co m*/ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { // no bluetooth support on this device, app should be stop Toast.makeText(getActivity().getApplicationContext(), "No Bluetooth Support!", Toast.LENGTH_LONG) .show(); getActivity().finish(); } if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); return; } // start create Sensors when bluetooth is enabled; startSensorModule(); }
From source file:johmphot.card.bluetooth.MultiplayerGameActivity.java
@Override public void onStart() { super.onStart(); // If BT is not on, request that it be enabled. // setupGame() will then be called during onActivityResult if (!btAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); }//from w w w . j a va2 s . c o m try { setupGame(); } catch (IOException e) { e.printStackTrace(); } }