Example usage for android.content.pm PackageManager FEATURE_BLUETOOTH_LE

List of usage examples for android.content.pm PackageManager FEATURE_BLUETOOTH_LE

Introduction

In this page you can find the example usage for android.content.pm PackageManager FEATURE_BLUETOOTH_LE.

Prototype

String FEATURE_BLUETOOTH_LE

To view the source code for android.content.pm PackageManager FEATURE_BLUETOOTH_LE.

Click Source Link

Document

Feature for #getSystemAvailableFeatures and #hasSystemFeature : The device is capable of communicating with other devices via Bluetooth Low Energy radio.

Usage

From source file:top.isense.demo.testsensor.DeviceScanActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    initial_naviview(this);
    //getActionBar().setTitle(R.string.title_devices);
    mHandler = new Handler();

    // 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();//w  ww  . ja  v  a 2s  .  com
    }

    // 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;
    }

}

From source file:com.example.shahrukhqasim2.deepmount.DeviceScanActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setTitle(R.string.title_devices);
    mHandler = new Handler();
    if (!checkPermission(this))
        showPermissionDialog();//from   w w w  .  ja  va  2s .  c om

    // 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();
    }

    // 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;
    }
}

From source file:com.android.waleed.arduino101led.DeviceScanActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    requestLocationUpdates();//from   www.j a v a 2  s .co  m

    super.onCreate(savedInstanceState);
    getActionBar().setTitle(R.string.title_devices);
    mHandler = new Handler();

    // 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();
    }

    // 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;
    }
}

From source file:com.xiaocheng.xc_application.bluetoothutils.DeviceScanActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_bluetooth_list);

    //getActionBar().setTitle(R.string.title_devices);
    mHandler = new Handler();

    //???// w ww .  ja  va2s  . com
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        //??
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                /*MY_PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION*/0);
        //?? ????
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) {
            Toast.makeText(this, "shouldShowRequestPermissionRationale", Toast.LENGTH_SHORT).show();
        }
    }

    // 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();
    }

    // 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 || !mBluetoothAdapter.isEnabled()) {
        /* Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
         finish();
         return;*/
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

    }

    lv_bleList = (ListView) findViewById(R.id.lv_bleList);

    mDevListAdapter = new DeviceListAdapter();
    lv_bleList.setAdapter(mDevListAdapter);

    lv_bleList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mDevListAdapter.getCount() > 0) {

                BluetoothDevice device1 = mDevListAdapter.getItem(position);
                if (device1 == null)
                    return;
                Intent intent1 = new Intent();
                intent1.putExtra(EXTRAS_DEVICE_NAME, device1.getName());
                intent1.putExtra(EXTRAS_DEVICE_ADDRESS, device1.getAddress());
                if (mScanning) {
                    mBluetoothAdapter.stopLeScan(mLeScanCallback);
                    mScanning = false;
                }

                // setResult  intent data Activity
                setResult(Activity.RESULT_OK, intent1);
                //? Activity
                finish();
                //                    startActivity(intent1);
            }
        }
    });
}

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 w  w w .j  a  va  2  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.mooshim.mooshimeter.main.ScanActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);

    // 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_LONG).show();
    }/*  ww  w .jav a2 s  .  c  om*/

    // Checks if Bluetooth is supported on the device.
    if (BluetoothAdapter.getDefaultAdapter() == null) {
        Toast.makeText(this, R.string.bt_not_supported, Toast.LENGTH_LONG).show();
        setError("BLE not supported on this device");
    }

    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        // Request BT adapter to be turned on
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQ_ENABLE_BT);
    }

    setContentView(R.layout.fragment_scan);
    // Initialize widgets
    mStatus = (TextView) findViewById(R.id.status);
    mBtnScan = (Button) findViewById(R.id.btn_scan);
    mDeviceScrollView = (LinearLayout) findViewById(R.id.device_list);
    mEmptyMsg = (TextView) findViewById(R.id.no_device);

    mDeviceScrollView.setClickable(true);

    mInflater = LayoutInflater.from(this);
}

From source file:iha_au.ppmonitor.Services.BleService.java

/**
 * Nr BleService bliver startet kaldes onCreate. Det er her alle attributter bliver instantieret.
 *//*from ww w  .  j a  va 2  s  . c  o  m*/
@Override
public void onCreate() {
    // BluetoothManager bruges til at manage og tilg BlueToothAdapter.
    bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    // BlueToothAdapter reprsentere enhedens lokale bluetoothadapter. Det er denne klasse, som bruges til at kalde Bluetooth tasks.
    mBluetoothAdapter = bluetoothManager.getAdapter();

    // Gennem denne klasse kan der scannes for Low Energy Bluetooth apparater.
    bluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
    hasBle = getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);

    //Metode til afkodning af UUIDS, da disse en collection af bytes. afkodes de til string, for nemmere sammenligning.
    try {
        getUuidsMethod = mBluetoothAdapter.getClass().getDeclaredMethod("getUuids", null);
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

    Log.v("DEBUG", "bleservce is started");
    super.onCreate();
}

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
    }/*  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:fr.bmartel.android.flowerpower.FlowerPowerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flower_power);

    // 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  ww  w .j ava2  s. com
    }

    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.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, FlowerPowerBtService.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.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 ww  w .  ja v a  2  s  . co  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;
}