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:oyagev.projects.android.ArduCopter.BluetoothChat.java
@Override public void onStart() { super.onStart(); if (D)//from w ww . j a v a 2s . co m Log.e(TAG, "++ ON START ++"); ycomm = new YCommunicator(); setupControls(); // 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.robotic.goldenridge.blecontroller.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 av a2 s. c o m } // Initializes list view adapter. if (Utility.isLE()) { mLeDeviceListAdapter = new LeDeviceListAdapter(); setListAdapter(mLeDeviceListAdapter); } else { mStandardDeviceListAdapter = new StandardDeviceListAdapter(); setListAdapter(mStandardDeviceListAdapter); } setscanatate(true); }
From source file:com.github.akinaru.bleanalyzer.activity.BaseActivity.java
protected boolean setupBluetooth() { //setup bluetooth if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, getResources().getString(R.string.ble_not_supported), Toast.LENGTH_SHORT).show(); finish();//from w w w . j a va2 s . c o m } else { //setup bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } return true; } return false; }
From source file:com.isoft.ible.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mLayout = findViewById(R.id.mainLayout); //If a user device turns off bluetooth, request to turn it on. //? ?? .//from w w w . ja va 2 s.c om 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); } Button btn = (Button) findViewById(R.id.rangeButton); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(MainActivity.this, RangeActivity.class); startActivity(i); finish(); } }); /** * 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.inducesmile.androidtabwithswipe.MainActivityb.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mainb); mLayout = findViewById(R.id.mainLayout); //If a user device turns off bluetooth, request to turn it on. //? ?? .//from w w w . jav a 2 s . c o m 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:it.angrydroids.epub3reader.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); navigator = new EpubNavigator(2, this); panelCount = 0;//from ww w . j a v a 2 s . c om settings = new String[8]; // LOADSTATE SharedPreferences preferences = getPreferences(MODE_PRIVATE); loadState(preferences); navigator.loadViews(preferences); if (panelCount == 0) { bookSelector = 0; Intent goToChooser = new Intent(this, FileChooser.class); startActivityForResult(goToChooser, 0); } bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } BLEServiceInit(); EPDMainServiceInit(); deviceList = new ArrayList<BluetoothDevice>(); devRssiValues = new HashMap<String, Integer>(); }
From source file:com.example.seonoh2.smarttoliet01.beacon.BeaconMainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.beacon_activity_main); mLayout = findViewById(R.id.mainLayout); //If a user device turns off bluetooth, request to turn it on. //? ?? .//from ww w . j av a 2 s . c om 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("BeaconMainActivity", "The location permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION) is not granted."); this.requestLocationPermission(); } else { Log.i("BeaconMainActivity", "The location permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION) is already granted."); } } }
From source file:com.sweetiepiggy.littlepro.LittleProActivity.java
private BluetoothDevice getBluetoothPair() { BluetoothDevice pairedDevice = null; BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { Toast.makeText(getApplicationContext(), new Error("Bluetooth not found").getMessage(), Toast.LENGTH_SHORT).show(); } else if (!bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, ACTIVITY_ENABLE_BLUETOOTH); } else {/* w w w . java2s.c o m*/ Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); Toast.makeText(getApplicationContext(), pairedDevices.size() + " paired devices found", Toast.LENGTH_SHORT).show(); switch (pairedDevices.size()) { case 0: // bluetoothAdapter.startDiscovery(); break; case 1: pairedDevice = pairedDevices.iterator().next(); break; /* choose device */ default: // for (pd : pairedDevices) { // } break; } } return pairedDevice; }
From source file:com.perples.recosample.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mLayout = findViewById(R.id.mainLayout); //If a user device turns off bluetooth, request to turn it on. //? ?? ./* ww w. j a v a 2s . c om*/ 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:net.kenevans.android.bleexplorer.DeviceScanActivity.java
@Override protected void onResume() { super.onResume(); Log.d(TAG, "onResume: mScanning=" + mScanning); // 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); }/* w ww .j a v a2 s. c o m*/ // Initializes list view adapter. if (mBluetoothAdapter.isEnabled()) { mLeDeviceListAdapter = new LeDeviceListAdapter(); setListAdapter(mLeDeviceListAdapter); startScan(); } }