List of usage examples for android.content Context BLUETOOTH_SERVICE
String BLUETOOTH_SERVICE
To view the source code for android.content Context BLUETOOTH_SERVICE.
Click Source Link
From source file:com.fallahpoor.infocenter.fragments.bluetooth.BluetoothFragment.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private BluetoothAdapter getBluetoothAdapter() { BluetoothAdapter bluetoothAdapter;/*w w w .j a v a 2 s. co m*/ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) { bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } else { bluetoothAdapter = ((BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE)) .getAdapter(); } return bluetoothAdapter; }
From source file:com.orange.beaconme_sdk.ble.control.BLEDeviceScanner.java
private void stopScanning() { stopReScanTimer();/*from w w w . j a v a2 s. c o m*/ BluetoothAdapter bluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)) .getAdapter(); if (bluetoothAdapter != null) { try { bluetoothAdapter.stopLeScan(mScanCallback); } catch (NullPointerException ex) { //prevent OBGM-215 issue. For proper fix more information needed } } getDeviceManager().clear(); }
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
@Override public void setContext(Context context) { Log.i(TAG, "setContext"); this.mContext = context; mBluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = mBluetoothManager.getAdapter(); }
From source file:com.microchip.pcs.DeviceScanActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.getActionBar().setTitle("MultiEVo"); //Display "BLE Device Scan" on the action bar mHandler = new Handler(); //Create Handler to stop scanning getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { //Check if BLE is supported Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); //Message that BLE not supported finish(); //End the app }//from www. j a v a 2s .co m final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); //Get the BluetoothManager mBluetoothAdapter = bluetoothManager.getAdapter(); //Get a reference to the BluetoothAdapter (radio) if (mBluetoothAdapter == null) { //Check if we got the BluetoothAdapter Toast.makeText(this, R.string.bluetooth_not_supported, Toast.LENGTH_SHORT).show(); //Message that Bluetooth not supported finish(); //End the app } }
From source file:io.v.android.impl.google.discovery.plugins.ble.Driver.java
/** * Create a new BLE driver for Android.//from ww w .j a v a2 s . c o m * * @param vContext Vanadium context. */ public Driver(VContext vContext) { mContext = V.getAndroidContext(vContext); if (mContext == null) { throw new IllegalStateException("AndroidContext not available"); } mServices = new HashMap<>(); BluetoothManager manager = ((BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE)); mBluetoothAdapter = manager.getAdapter(); if (mBluetoothAdapter == null) { Log.w(TAG, "BluetoothAdapter not available"); return; } if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.w(TAG, "ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION not granted, " + "Bluetooth discovery will not be happening"); return; } mContext.registerReceiver(new BluetoothAdapterStatusReceiver(), new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); if (!mBluetoothAdapter.isEnabled()) { // Prompt user to turn on Bluetooth. Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); enableBtIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(enableBtIntent); return; } resume(); }
From source file:com.karma.konnect.BeaconConfigFragment.java
private void initializeBluetooth() { // Initializes a Bluetooth adapter. For API version 18 and above, // get a reference to BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); }
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 w w w . ja v a 2 s .co m 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.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 v 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); } 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.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); } /** * 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.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. //? ?? .//w ww . ja v a2s .co 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("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."); } } }