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.shrlnm.android.erm.ElmRenaultMonitor_Main.java
@Override public void onStart() { super.onStart(); if (D)//www . j a v a 2 s . c o m Log.e(TAG, "++ ON START ++"); // 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(); } if (STATE_CONNECTED != mChatService.getState()) { // load saved mac address. String mac_address = sharedPref.getString(getString(R.string.preference_addr_key), ""); if ((mac_address != null ? mac_address.length() : 0) == 17) { // it is and we just connect to it connectDevice(mac_address); } else { // there is no saved address then ask it try { Intent serverIntent = new Intent(this, DeviceListActivity.class); startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); } catch (android.content.ActivityNotFoundException e) { if (D) Log.e(TAG, "+++ ActivityNotFoundException +++"); } } } }
From source file:com.orange.beaconme_sdk.control.BeaconMonitor.java
/** * Check if Bluetooth is enabled. If it is enabled then start scanner, ask to enable Bluetooth otherwise. *//*from w w w . j ava2 s . com*/ private void startScan() { BluetoothAdapter btAdapter = ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)) .getAdapter(); if (btAdapter == null || !btAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); enableBtIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(enableBtIntent); } else { context.sendBroadcast(new Intent(BLEDeviceScanner.START_SCAN_SERVICE_ACTION)); } }
From source file:com.a3did.partner.recosample.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_reco); mLayout = findViewById(R.id.mainLayout); View includedLayout = (View) findViewById(R.id.reco_settings_values); TextView mRecoOnlyText = (TextView) includedLayout.findViewById(R.id.recoRecoonlySetting); if (SCAN_RECO_ONLY) { mRecoOnlyText.setText(R.string.settings_result_true); } else {/*from ww w.ja v a 2s . co m*/ mRecoOnlyText.setText(R.string.settings_result_false); } TextView mDiscontinuousText = (TextView) includedLayout.findViewById(R.id.recoDiscontinouosSetting); if (DISCONTINUOUS_SCAN) { mDiscontinuousText.setText(R.string.settings_result_true); } else { mDiscontinuousText.setText(R.string.settings_result_false); } TextView mBackgroundRangingTimeoutText = (TextView) includedLayout .findViewById(R.id.recoBackgroundtimeoutSetting); if (ENABLE_BACKGROUND_RANGING_TIMEOUT) { mBackgroundRangingTimeoutText.setText(R.string.settings_result_true); } else { mBackgroundRangingTimeoutText.setText(R.string.settings_result_false); } //If a user device turns off bluetooth, request to turn it on. //? ?? . mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { Intent enableBTIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBTIntent, REQUEST_ENABLE_BT); } /** * In order to use RECO SDK for Android API 23 (Marshmallow) or higher, * the location permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION) is required. * Please refer to the following permission guide and sample code provided by Google. * * ? API 23 ()?? , ?? RECO SDK * (ACCESS_COARSE_LOCATION ? ACCESS_FINE_LOCATION)? . * ? , ? ? ?. * * http://www.google.com/design/spec/patterns/permissions.html * https://github.com/googlesamples/android-RuntimePermissions */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.i("MainActivity", "The location permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION) is not granted."); this.requestLocationPermission(); } else { Log.i("MainActivity", "The location permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION) is already granted."); } } }
From source file:com.agustinprats.myhrv.MainActivity.java
/** 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. */ public void requestEnableBt() { if (!isBluetoothEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); }/*from ww w. jav a 2s . c o m*/ }
From source file:com.evothings.BLE.java
private void checkPowerState(BluetoothAdapter adapter, CallbackContext cc, Runnable onPowerOn) { if (adapter == null) { return;/*from w w w . j a v a2s. co m*/ } if (adapter.getState() == BluetoothAdapter.STATE_ON) { // Bluetooth is ON onPowerOn.run(); } else { mOnPowerOn = onPowerOn; mPowerOnCallbackContext = cc; Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); cordova.startActivityForResult(this, enableBtIntent, 0); } }
From source file:com.microchip.pcs.DeviceScanActivity.java
@Override protected void onResume() { super.onResume(); ContextCompat.checkSelfPermission(DeviceScanActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION); if (ContextCompat.checkSelfPermission(DeviceScanActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(DeviceScanActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION)) { } else {/* w w w.j av a2 s .c om*/ ActivityCompat.requestPermissions(DeviceScanActivity.this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, 1); } } ContextCompat.checkSelfPermission(DeviceScanActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (ContextCompat.checkSelfPermission(DeviceScanActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(DeviceScanActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { } else { ActivityCompat.requestPermissions(DeviceScanActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1); } } if (!mBluetoothAdapter.isEnabled()) { //Check if BT is not enabled Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); //Create an intent to get permission to enable BT startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); //Fire the intent to start the activity that will return a result based on user response } mLeDeviceListAdapter = new LeDeviceListAdapter(); //Create new list adapter to hold list of BLE devices found during scan setListAdapter(mLeDeviceListAdapter); //Bind our ListActivity to the new list adapter scanLeDevice(true); }
From source file:app.wz.MainActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); self = this;//from w ww. j a v a2s. c o m requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setProgressBarIndeterminateVisibility(false); setContentView(R.layout.layout_main); // initialize your android device sensor capabilities mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); lock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "LockTag"); prefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); textScroll = (ScrollView) findViewById(R.id.textScroll); textRead = (TextView) findViewById(R.id.textRead); commStatus = (TextView) findViewById(R.id.commStatus); pingStatus = (TextView) findViewById(R.id.pingStatus); inputCmd = (EditText) findViewById(R.id.inputCmd); inputVal = (EditText) findViewById(R.id.inputVal); gb = (GlobalApp) getApplication(); gb.bt = new BluetoothSPP(this); bt = gb.bt; gb.arduino = new ArduinoFirmata(this, bt); arduino = gb.arduino; gb.neuro = new NeuroInterface(prefs, gb); neuro = gb.neuro; if (prefs.getBoolean("autoload", false)) { if (neuro.loadWeights(prefs.getString("last_save", ""))) { textRead.append("Restored Weights at Step " + neuro.count + "\n"); textScroll.fullScroll(View.FOCUS_DOWN); } } if (!bt.isBluetoothAvailable()) { Toast.makeText(getApplicationContext(), "Bluetooth is not available", Toast.LENGTH_SHORT).show(); finish(); } bt.setOnDataReceivedListener(new OnDataReceivedListener() { public void onDataReceived(byte[] data, String message) { gb.lastResponseBT = System.currentTimeMillis(); arduino.processInput(data); } }); bt.setBluetoothConnectionListener(new BluetoothConnectionListener() { public void onDeviceDisconnected() { haltNeuro(); commStatus.setText("Status : Not Connected"); menu.clear(); getMenuInflater().inflate(R.menu.connection, menu); } public void onDeviceConnectionFailed() { commStatus.setText("Status : Connection Failed"); } public void onDeviceConnected(String name, String address) { commStatus.setText("Status : Connected to " + name); menu.clear(); getMenuInflater().inflate(R.menu.disconnection, menu); } }); // bt.setAutoConnectionListener(new BluetoothSPP.AutoConnectionListener() { // public void onNewConnection(String name, String address) { // Log.i("Check", "New Connection - " + name + " - " + address); // } // // public void onAutoConnectionStarted() { // Log.i("Check", "Auto connection started"); // } // }); if (!bt.isBluetoothEnabled()) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, BluetoothState.REQUEST_ENABLE_BT); } else { if (!bt.isServiceAvailable()) { bt.setupService(); bt.startService(BluetoothState.DEVICE_ANDROID); setup(); } } refreshPing.start(); neuroThread.start(); new Thread() { public void run() { while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } if (neuro.count > neuro.lastDisplay) { neuro.lastDisplay = neuro.count; runOnUiThread(new Runnable() { @Override public void run() { if (!neuro.halt) { textRead.append( "P err: " + (new DecimalFormat("0.000E0")).format(neuro.avg_error) + " O err: " + (new DecimalFormat("0.000E0")).format(neuro.avg_obj_error) + " stp: " + neuro.count + "\n"); textScroll.fullScroll(View.FOCUS_DOWN); } } }); } } } }.start(); new Thread() { public void run() { while (true) { try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } runOnUiThread(new Runnable() { @Override public void run() { if (textRead.length() > 20000) textRead.setText(""); } }); } } }.start(); }
From source file:pl.mrwojtek.sensrec.app.HeartRateDialog.java
private void requestEnableBluetooth() { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, BLUETOOTH_ENABLE_REQUEST_CODE); }
From source file:com.example.hudpassthrough.BluetoothChat.java
@Override public void onStart() { super.onStart(); if (D)//w ww.ja va 2 s . com Log.e(TAG, "++ ON START ++"); // 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 source file:com.mohammedx.cart.android.client.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();/* w w w . j a v a 2 s . c o m*/ Intent serverIntent = new Intent(getActivity(), ScanActivity.class); startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE); } }