List of usage examples for android.content.pm PackageManager FEATURE_BLUETOOTH_LE
String FEATURE_BLUETOOTH_LE
To view the source code for android.content.pm PackageManager FEATURE_BLUETOOTH_LE.
Click Source Link
From source file:com.github.akinaru.roboticbuttonpusher.activity.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(layoutId);/*from ww w . ja v a 2 s. c o m*/ debugTv = (TextView) findViewById(R.id.debug_mode_tv); // Set a Toolbar to replace the ActionBar. toolbar = (Toolbar) findViewById(R.id.toolbar_item); setSupportActionBar(toolbar); getSupportActionBar().setTitle(getResources().getString(R.string.bt_device_title)); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.inflateMenu(R.menu.toolbar_menu); // Find our drawer view mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawerToggle = setupDrawerToggle(); mDrawer.setDrawerListener(drawerToggle); nvDrawer = (NavigationView) findViewById(R.id.nvView); // Setup drawer view setupDrawerContent(nvDrawer); mDisassociateMenuItem = nvDrawer.getMenu().findItem(R.id.exit_item); //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 source file:com.mikroe.hexiwear_android.DeviceScanActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listitem_device); mHandler = new Handler(); mDeviceAddresses = new ArrayList<String>(); mScanTitle = (TextView) findViewById(R.id.scanTitle); mDeviceAddresses.add(KWARP_ADDRESS); mDeviceAddresses.add(KWARP_ADDRESS_TWO); // 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, R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); finish();/*from w w w. j av a2 s .c o m*/ } // Initializes a Bluetooth adapter. For API level 18 and above, get a reference to // BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); // Checks if Bluetooth is supported on the device. if (mBluetoothAdapter == null) { Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show(); finish(); return; } // 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); } } //checkNotificationEnabled(); LocalBroadcastManager.getInstance(this).registerReceiver(onNotice, new IntentFilter("Msg")); ComponentName name = startService(new Intent(DeviceScanActivity.this, NotificationService.class)); registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter()); scanLeDevice(true); Intent gattServiceIntent = new Intent(DeviceScanActivity.this, BluetoothLeService.class); bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); }
From source file:com.lge.helloFriendsCamera.ConnectionActivity.java
private void setupView() { setContentView(R.layout.connect_layout); getSupportActionBar().setTitle(R.string.camera_connect); getSupportActionBar().setDisplayHomeAsUpEnabled(true); textScanState = (TextView) findViewById(R.id.text_scan); // 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, "ble not supported", Toast.LENGTH_SHORT).show(); buttonStartScan.setEnabled(false); buttonStopScan.setEnabled(false); } else {//from w ww. j a v a 2s .c o m buttonStartScan = (Button) findViewById(R.id.button_startscan); buttonStartScan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. checkBleScanPermissionAndStartScan(); } }); buttonStopScan = (Button) findViewById(R.id.button_stopscan); buttonStopScan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Stop scanning BLE devices stopScanDevice(); } }); buttonStartScan.setEnabled(true); buttonStopScan.setEnabled(true); } listViewResult = (ListView) findViewById(R.id.listView_scanResult); }
From source file:org.uribeacon.sample.UriBeaconScanActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.uribeacon_scan_layout); mSwipeWidget = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_widget); mSwipeWidget.setOnRefreshListener(this); // Initializes list view adapter. mLeDeviceListAdapter = new DeviceListAdapter(getLayoutInflater()); setListAdapter(mLeDeviceListAdapter); // 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, R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); finish();/*from www. j a v a 2 s .c om*/ } // Initializes a Bluetooth adapter. For API version 18 and above, // get a reference to BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); // Checks if Bluetooth is supported on the device. if (mBluetoothAdapter == null) { Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show(); finish(); } }
From source file:com.github.akinaru.bleremote.activity.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(layoutId);//from www .j a va2 s. c om if (Build.VERSION.SDK_INT >= 21) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark)); } // Set a Toolbar to replace the ActionBar. toolbar = (Toolbar) findViewById(R.id.toolbar_item); setSupportActionBar(toolbar); getSupportActionBar().setTitle(getResources().getString(R.string.bt_device_title)); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.inflateMenu(R.menu.toolbar_menu); // Find our drawer view mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawerToggle = setupDrawerToggle(); mDrawer.setDrawerListener(drawerToggle); nvDrawer = (NavigationView) findViewById(R.id.nvView); // Setup drawer view setupDrawerContent(nvDrawer); //setup bluetooth if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, getResources().getString(R.string.ble_not_supported), Toast.LENGTH_SHORT).show(); finish(); } //setup bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); }
From source file:dev.coatl.co.urband_basic.presenter.activities.StartSearchDevice.java
private void setResources() { handler = new Handler(); listDevices = (ListView) findViewById(R.id.urband_device_list); listDevices.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w w w .j a v a 2 s .co m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final BluetoothDevice device = ((BluetoothUrbandDeviceItem) parent.getItemAtPosition(position)) .getDevice(); if (device == null) { return; } intent = new Intent(getApplicationContext(), ActivityHomePanel.class); intent.putExtra(EXTRAS_DEVICE_NAME, device.getName()); intent.putExtra(EXTRAS_DEVICE_ADDRESS, device.getAddress()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (scanning) { bluetoothAdapter.stopLeScan(scanDevices); scanning = false; } startActivity(intent); } }); if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, "Este dispositivo no soporta Bluetooth", Toast.LENGTH_SHORT).show(); finish(); } final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }
From source file:com.amti.vela.bluetoothlegatt.bluetooth.DeviceScanActivity.java
boolean isBtCompat() { // 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, "This device does not support bluetooth", Toast.LENGTH_SHORT).show(); finish();/*from w w w . j a v a 2 s.com*/ return false; } // Checks if Bluetooth is supported on the device. if (mBluetoothAdapter == null) { Toast.makeText(this, "This device does not support bluetooth", Toast.LENGTH_SHORT).show(); finish(); return false; } return true; }
From source file:net.emilymaier.movebot.HeartFragment.java
@Override @SuppressWarnings("deprecation") public void onClick(View view) { Log.d("HeartFragment", "Scan button clicked"); final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { new NoBluetoothDialogFragment().show(act.getSupportFragmentManager(), "bluetooth"); return;//from w w w.j av a 2s.c o m } if (!bluetoothAdapter.isEnabled()) { new BluetoothDisabledDialogFragment().show(act.getSupportFragmentManager(), "disabled"); return; } if (!act.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { new NoLeDialogFragment().show(act.getSupportFragmentManager(), "le"); return; } Log.d("HeartFragment", "Starting scan"); heartScan.setClickable(false); heartScan.setText("Scanning..."); for (HeartDevice device : heartDevices) { device.bluetoothGatt.disconnect(); device.bluetoothGatt.close(); } heartDevices.clear(); heartListAdapter.notifyDataSetChanged(); bluetoothAdapter.startLeScan(new UUID[] { UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb") }, this); final HeartFragment t = this; new Handler().postDelayed(new Runnable() { @Override public void run() { Log.d("HeartFragment", "Stopping scan"); bluetoothAdapter.stopLeScan(t); heartScan.setText("Scan"); heartScan.setClickable(true); heartListAdapter.notifyDataSetChanged(); } }, 5000); }
From source file:dev.coatl.co.urband_basic.presenter.activities.StartSearchDevice.java
private void setBluetooth() { /* Verify that Android device has Bluetooth LE feature*/ if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { finish();/*from w ww . j a v a2 s. co m*/ } /* Check if Bluetooth is enabled (ON)*/ if (!bluetoothAdapter.isEnabled()) { /* Start system activity for request to turn on the bluetooth */ Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } // Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_COARSE_LOCATION)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, my_req_perm1); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } // Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Show an explanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, my_req_perm2); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } // Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, my_req_perm3); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } scanLeDevice(true); }
From source file:com.buddi.client.dfu.FeaturesActivity.java
private boolean ensureBLEExists() { if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, R.string.no_ble, Toast.LENGTH_LONG).show(); return false; }//from ww w . j a v a2s .co m return true; }