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.rfdroid.activity.BtDevicesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_btdevices); deviceNameTv = (TextView) findViewById(R.id.device_name); sharedpreferences = getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE); int scanIntervalValue = sharedpreferences.getInt(JsonConstants.BT_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL); int scanWindowValue = sharedpreferences.getInt(JsonConstants.BT_SCAN_WINDOW, DEFAULT_SCAN_WINDOW); tablelayout = (TableLayout) findViewById(R.id.tablelayout); altTableRow(2);//from w w w . j av a 2s . c o m // Set a Toolbar to replace the ActionBar. toolbar = (Toolbar) findViewById(R.id.toolbar_item); setSupportActionBar(toolbar); getSupportActionBar().setTitle("BLE device - reception rate"); 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); // 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(); } mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter()); mChart = (BarChart) findViewById(R.id.chart1); mChart.setDrawBarShadow(false); mChart.setDrawValueAboveBar(true); mChart.setDescription(""); // if more than 60 entries are displayed in the chart, no values will be // drawn mChart.setMaxVisibleValueCount(60); // scaling can now only be done on x- and y-axis separately mChart.setPinchZoom(false); mChart.setDrawGridBackground(false); mChart.setDescriptionColor(Color.parseColor("#000000")); XAxis xAxis = mChart.getXAxis(); xAxis.setDrawGridLines(false); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setSpaceBetweenLabels(0); YAxisValueFormatter custom = new DataAxisFormatter("%"); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setValueFormatter(custom); leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setValueFormatter(custom); rightAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setDrawGridLines(true); rightAxis.setDrawGridLines(false); mChart.animateY(1000); mChart.getLegend().setEnabled(true); mChart.setVisibility(View.GONE); mScanIntervalSeekbar = (DiscreteSeekBar) findViewById(R.id.scan_interval_seekbar); mScanIntervalSeekbar.setVisibility(View.GONE); mScanIntervalSeekbar.keepShowingPopup(true); mScanIntervalSeekbar.setNumericTransformer(new DiscreteSeekBar.NumericTransformer() { @Override public int transform(int value) { return value * 10; } }); mScanIntervalSeekbar.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { mScanIntervalSeekbar.showFloater(250); } } }); mScanIntervalSeekbar.setOnProgressChangeListener(new DiscreteSeekBar.OnProgressChangeListener() { @Override public void onProgressChanged(DiscreteSeekBar seekBar, int value, boolean fromUser) { if (scanIntervalTv != null) scanIntervalTv.setText("" + (value * 10)); } @Override public void onStartTrackingTouch(DiscreteSeekBar seekBar) { } @Override public void onStopTrackingTouch(DiscreteSeekBar seekBar) { //setScanInterval(); } }); mWindowIntervalSeekbar = (DiscreteSeekBar) findViewById(R.id.scan_window_seekbar); mWindowIntervalSeekbar.setVisibility(View.GONE); mWindowIntervalSeekbar.keepShowingPopup(true); mWindowIntervalSeekbar.setNumericTransformer(new DiscreteSeekBar.NumericTransformer() { @Override public int transform(int value) { return value * 10; } }); mWindowIntervalSeekbar.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { mWindowIntervalSeekbar.showFloater(250); } } }); mWindowIntervalSeekbar.setOnProgressChangeListener(new DiscreteSeekBar.OnProgressChangeListener() { @Override public void onProgressChanged(DiscreteSeekBar seekBar, int value, boolean fromUser) { if (scanWindowTv != null) scanWindowTv.setText("" + (value * 10)); } @Override public void onStartTrackingTouch(DiscreteSeekBar seekBar) { } @Override public void onStopTrackingTouch(DiscreteSeekBar seekBar) { //setWindowInterval(); } }); mScanIntervalSeekbar.setProgress(scanIntervalValue / 10); mWindowIntervalSeekbar.setProgress(scanWindowValue / 10); scanIntervalTv = (TextView) findViewById(R.id.scan_interval_value); scanWindowTv = (TextView) findViewById(R.id.scan_window_value); scanIntervalTv.setText("" + scanIntervalValue); scanWindowTv.setText("" + scanWindowValue); Button button_stop = (Button) findViewById(R.id.button_stop); Button button_restart_scan = (Button) findViewById(R.id.button_restart_scan); button_stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentService != null && currentService.isScanning()) { Log.i(TAG, "scanning stopped..."); runOnUiThread(new Runnable() { @Override public void run() { hideProgressBar(); Toast.makeText(BtDevicesActivity.this, "scanning has stopped", Toast.LENGTH_SHORT) .show(); } }); currentService.stopScan(); } } }); button_restart_scan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { currentService.stopScan(); Log.i(TAG, "scanning ..."); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(BtDevicesActivity.this, "scanning ...", Toast.LENGTH_SHORT).show(); } }); scanningListView.setItemChecked(-1, true); triggerNewScan(); } }); initTv(); if (mBluetoothAdapter.isEnabled()) { Intent intent = new Intent(this, RFdroidService.class); bound = bindService(intent, mServiceConnection, BIND_AUTO_CREATE); } }
From source file:com.agustinprats.myhrv.MainActivity.java
@Override public void onResume() { super.onResume(); _inForeground = true;//from www .java 2 s. c o m if (_heartRateService != null) { _heartRateService.setInForeground(_inForeground); } // If the device doesn't support BLE show message and exit if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { showBleRequireDialog(); } }
From source file:kr.ac.kaist.resl.sensorservice.BluetoothService.java
@SuppressLint("HandlerLeak") @Override/*from w ww .j a v a 2 s .c o m*/ public void onStart(Intent intent, int startId) { androidId = android.provider.Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID); invokeBLEmanagerService(); invokeBLEservice(); // Check if the android phone supports BLE if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); } // Init msg handler for device scanner scannerMsgHandler = new Handler() { public void handleMessage(Message msg) { String deviceName = msg.getData().getString(DeviceScanner.MSG_KEY_DEVICE_NAME); String deviceAddress = msg.getData().getString(DeviceScanner.MSG_KEY_DEVICE_ADDRESS); if (deviceName.equals("MIO GLOBAL LINK")) { connectTo(deviceName, deviceAddress); } } }; // Init scanner scanner = new DeviceScanner((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE), scannerMsgHandler); mBluetoothAdapter = scanner.initialize(); if (mBluetoothAdapter == null) { Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show(); return; } // Init device-service-characteristic table. init_Device_Service_CharacteristicTable(); // Register braodcast receiver registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter()); if (!scanner.isScanning()) { scanner.scanLeDevice(true); } else bleService.reconnect(); }
From source file:com.example.user.wase.view.fragment.EquipmentScanner.java
@Nullable @Override/*w ww .jav a 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); // Use this check to determine whether BLE is supported on the device. Then you can // selectively disable BLE-related features. if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(getActivity(), "You need BLE support device", Toast.LENGTH_SHORT).show(); getActivity().finish(); } // Initializes a Bluetooth adapter. For API level 18 and above, get a reference to // BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); // Checks if Bluetooth is supported on the device. if (mBluetoothAdapter == null) { Toast.makeText(getActivity(), "You need BLUETOOTH support device", Toast.LENGTH_SHORT).show(); getActivity().finish(); } Intent gattServiceIntent = new Intent(getActivity(), BluetoothLeService.class); getActivity().registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter()); getActivity().bindService(gattServiceIntent, mServiceConnection, getActivity().BIND_AUTO_CREATE); scanLeDevice(true); equipListAdapter = new HERE_DeviceListAdapter(); View view = inflater.inflate(R.layout.fragment_devicelist, container, false); lvEquipList = (ListView) view.findViewById(R.id.fragment1_equiplist); lvEquipList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { scanLeDevice(false); final MyHereAgent device = pairedEquipList.get(position); if (device == null) return; final Intent intent = new Intent(getActivity(), DoingExerciseActivity.class); intent.putExtra(DoingExerciseActivity.EXTRAS_DEVICE_NAME, device.getMyeqName()); intent.putExtra(DoingExerciseActivity.EXTRAS_DEVICE_ADDRESS, device.getMyeqMacId()); if (mScanning) { mBluetoothAdapter.stopLeScan(mLeScanCallback); mScanning = false; } if (mBluetoothLeService != null) { mBluetoothLeService.disconnect(); mBluetoothLeService.close(); mBluetoothLeService = null; } startActivity(intent); } }); lvEquipList.setAdapter(equipListAdapter); tv_numagents = (TextView) view.findViewById(R.id.equiplist_numagents); tv_numagents.setText(String.format("%d", equipListAdapter.getCount())); //getActionBar().setTitle(mDeviceName); //getActionBar().setDisplayHomeAsUpEnabled(true); return view; }
From source file:com.molidt.easyandroid.bluetooth.BluetoothFragmentV4.java
protected void initPlugin(Activity activity) { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); _activity = activity;// w w w . j ava 2s .com if (mBluetoothAdapter == null) { isSupportBluetooth = false; isSupportBLE = false; } else { isSupportBluetooth = true; if (_activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { isSupportBLE = true; } else { isSupportBLE = false; } } isInit = true; }
From source file:com.wearme.fat.ui.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }//from www .j a va 2s . co m this.requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setBehindContentView(R.layout.test); mContext = MainActivity.this; mDataBaseManager = DatabaseManager.getInstance(mContext); mInflater = getLayoutInflater(); initUserDataList(); initViewPager(); initSlideMenuView(); initShackListener(); mOptionsStyle = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.ic_launcher) .showImageForEmptyUri(R.drawable.ic_launcher).showImageOnFail(R.drawable.ic_launcher) .cacheInMemory(true).cacheOnDisk(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565) .build(); mHandler = new Handler(); if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); } final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show(); finish(); return; } Intent gattServiceIntent = new Intent(this, BluetoothLeService.class); getApplicationContext().bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); }
From source file:br.liveo.ndrawer.ui.activity.MainActivity.java
License:asdf
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @Override/* w ww . j av a 2 s . co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MovementProfile.status = 0; startingPosition = 0; registBroadcastReceiver(); getInstanceIdToken(); mDeviceAdapter = new DeviceListAdapter(this, R.layout.device_item); mHandler = new Handler(); if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, "BLE Not Supported", Toast.LENGTH_SHORT).show(); finish(); } mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = mBluetoothManager.getAdapter(); timer = new Timer(); mBluetoothDeviceList = new ArrayList<BluetoothDevice>(); // Register the BroadcastReceiver mFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); mFilter.addAction(ACTION_GATT_CONNECTED); mFilter.addAction(ACTION_GATT_DISCONNECTED); mFilter.addAction(ACTION_GATT_SERVICES_DISCOVERED); mFilter.addAction(ACTION_DATA_NOTIFY); mFilter.addAction(ACTION_DATA_WRITE); mFilter.addAction(ACTION_DATA_READ); if (isRegister == 0) { registerReceiver(mReceiver, mFilter); } mainActivity = this; Thread queueThread = new Thread() { @Override public void run() { while (true) { executeQueue(); try { Thread.sleep(0, 100000); } catch (Exception e) { e.printStackTrace(); } } } }; queueThread.start(); }
From source file:ble.AndroidBle.java
public AndroidBle(BleService service) { mService = service;/*from www. ja v a2 s .c om*/ // btQuery = BTQuery.getInstance(); if (!mService.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { mService.bleNotSupported(); return; } final BluetoothManager bluetoothManager = (BluetoothManager) mService .getSystemService(Context.BLUETOOTH_SERVICE); mBtAdapter = bluetoothManager.getAdapter(); if (mBtAdapter == null) { mService.bleNoBtAdapter(); } mBluetoothGatts = new HashMap<String, BluetoothGatt>(); }
From source file:com.hardcopy.blechat.MainActivity.java
/** * Initialization / Finalization//www . j ava2 s. c om */ private void initialize() { Logs.d(TAG, "# Activity - initialize()"); // 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.bt_ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); } mService.setupService(mActivityHandler); // If BT is not on, request that it be enabled. // RetroWatchService.setupBT() will then be called during onActivityResult if (!mService.isBluetoothEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, Constants.REQUEST_ENABLE_BT); } // Load activity reports and display if (mRefreshTimer != null) { mRefreshTimer.cancel(); } // Use below timer if you want scheduled job //mRefreshTimer = new Timer(); //mRefreshTimer.schedule(new RefreshTimerTask(), 5*1000); }
From source file:com.google.android.apps.forscience.ble.MyBleService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Intent newIntent = new Intent(BleEvents.BLE_UNSUPPORTED); LocalBroadcastManager.getInstance(this).sendBroadcast(newIntent); return START_NOT_STICKY; }//from w w w . j av a 2s.c o m if (bluetoothManager == null) { bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); } if (btAdapter == null) { btAdapter = bluetoothManager.getAdapter(); } if (!checkBleEnabled()) { return START_NOT_STICKY; } // Intent newIntent = new Intent(BleEvents.BLE_ENABLED); // LocalBroadcastManager.getInstance(this).sendBroadcast(newIntent); return START_STICKY; }