List of usage examples for android.bluetooth BluetoothManager getAdapter
public BluetoothAdapter getAdapter()
From source file:com.github.akinaru.roboticbuttonpusher.bluetooth.BluetoothCustomManager.java
@SuppressLint("NewApi") public void init(Context context) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) context .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); //init message handler mHandler = null;//from ww w.j a va 2 s . c o m mHandler = new Handler(); scanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(BluetoothDevice device, int rssi, final byte[] scanRecord) { if (device.getAddress() != null && device.getName() != null) { dispatchBtDevices(device, rssi, scanRecord); } } }; }
From source file:net.kenevans.android.bleexplorer.DeviceScanActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setTitle(R.string.title_devices); }//from www . j ava 2s . c om 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_LONG).show(); finish(); } // Initializes a Bluetooth adapter. For API level 18 and above, get a // reference to BluetoothAdapter through BluetoothManager. mBluetoothAdapter = null; final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (bluetoothManager == null) { Toast.makeText(this, R.string.error_bluetooth_manager, Toast.LENGTH_LONG).show(); finish(); return; } try { mBluetoothAdapter = bluetoothManager.getAdapter(); } catch (NullPointerException ex) { Toast.makeText(this, R.string.error_bluetooth_adapter, Toast.LENGTH_LONG).show(); } // Checks if Bluetooth is supported on the device. if (mBluetoothAdapter == null) { String msg = getString(R.string.bluetooth_not_supported); Utils.errMsg(this, msg); Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); finish(); } // Set result CANCELED in case the user backs out setResult(Activity.RESULT_CANCELED); }
From source file:no.nordicsemi.android.BLE.profile.BleProfileServiceReadyActivity.java
private void setBluetoothAdapter() { final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); }
From source file:com.github.akinaru.bleanalyzer.bluetooth.BluetoothCustomManager.java
@SuppressLint("NewApi") public void init(Context context) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) context .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); //init message handler mHandler = null;// ww w. j a va 2s . c o m mHandler = new Handler(); scanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(BluetoothDevice device, int rssi, final byte[] scanRecord) { if (device.getAddress() != null && device.getName() != null) { if (device.getName().equals("RFdroid")) { dispatchRFdroid(device, rssi, scanRecord); } else { dispatchBtDevices(device, rssi, scanRecord); } } } }; }
From source file:com.example.RITW.Ble.BleProfileServiceReadyActivity.java
protected boolean isBLEEnabled() { final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter adapter = bluetoothManager.getAdapter(); return adapter != null && adapter.isEnabled(); }
From source file:com.example.user.wase.view.fragment.EquipmentScanner.java
@Nullable @Override/*w w w .j a v a2 s . c om*/ 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.wearme.fat.ui.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }/* w w w . j a v a 2 s . c o 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:com.buddi.client.dfu.DfuActivity.java
private boolean isBLEEnabled() { final BluetoothManager manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter adapter = manager.getAdapter(); return adapter != null && adapter.isEnabled(); }
From source file:de.dmarcini.bt.homelight.HomeLightMainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (BuildConfig.DEBUG) { Log.v(TAG, "erzeuge Application..."); }//from w w w. j ava2 s. com setContentView(R.layout.activity_home_light_main); if (BuildConfig.DEBUG) { Log.e(TAG, "D E B U G Version"); } //############################################################################################## // // Ist Bluethooth LE (4.0) untersttzt? // if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, R.string.main_ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); } // // initialisiere den Adapter // final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); btConfig.setBluetoothAdapter(bluetoothManager.getAdapter()); // // Ist ein BT Adapter vorhanden? // if (btConfig.getBluethoothAdapter() == null) { Toast.makeText(this, R.string.main_ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); return; } // // Systemeinstellungen einlesen // HomeLightSysConfig.readSysPrefs(getResources(), PreferenceManager.getDefaultSharedPreferences(this)); // // Kommando-Queue Tread aktivieren // cmdTread = new CmdQueueThread(recCmdQueue, CReciver); Thread tr = new Thread(cmdTread, "cmd_queue_thread"); tr.start(); // // Vorerst nur der Platzhalter fr ein Spielerchen spter // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fabOnOff); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); setModulOnOff(); //Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show(); } }); if (BuildConfig.DEBUG) { Log.v(TAG, "erzeuge Application...OK"); } }
From source file:de.frank_durr.ble_v_monitor.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); restoreDataModel(savedInstanceState); if (bluetoothAdapter == null) { BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }/* w w w . j av a2 s . c o m*/ if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_KEY_BLUETOOTH_DEVICE)) { bluetoothDevice = savedInstanceState.getParcelable(BUNDLE_KEY_BLUETOOTH_DEVICE); } PreferenceManager.setDefaultValues(this, R.xml.preferences, false); gattHandler = new GattCallbackHandler(); taskTimoutHandler = new Handler(); updateTriggerHandler = new ModelUpdateTriggerHandler(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); String appName = getString(R.string.app_name); toolbar.setTitle(appName); setSupportActionBar(toolbar); FragmentManager fm = getSupportFragmentManager(); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); FPAdapter fpAdapter = new FPAdapter(fm); viewPager.setAdapter(fpAdapter); // Get references to already existing tags if (savedInstanceState != null) { if (savedInstanceState.containsKey(BUNDLE_KEY_CURRENT_VOLTAGE_FRAGMENT)) { String tag = savedInstanceState.getString(BUNDLE_KEY_CURRENT_VOLTAGE_FRAGMENT); fragmentCurrentVoltage = (CurrentVoltageFragment) fm.findFragmentByTag(tag); } if (savedInstanceState.containsKey(BUNDLE_KEY_MINUTELY_HISTORY_FRAGMENT)) { String tag = savedInstanceState.getString(BUNDLE_KEY_MINUTELY_HISTORY_FRAGMENT); fragmentMinutelyHistory = (HistoryFragment) fm.findFragmentByTag(tag); } if (savedInstanceState.containsKey(BUNDLE_KEY_HOURLY_HISTORY_FRAGMENT)) { String tag = savedInstanceState.getString(BUNDLE_KEY_HOURLY_HISTORY_FRAGMENT); fragmentHourlyHistory = (HistoryFragment) fm.findFragmentByTag(tag); } if (savedInstanceState.containsKey(BUNDLE_KEY_DAILY_HISTORY_FRAGMENT)) { String tag = savedInstanceState.getString(BUNDLE_KEY_DAILY_HISTORY_FRAGMENT); fragmentDailyHistory = (HistoryFragment) fm.findFragmentByTag(tag); } } TabLayout tabLayout = (TabLayout) findViewById(R.id.tablayout); tabLayout.setupWithViewPager(viewPager); }