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.vehicle.uart.UartService.java
/** * Initializes a reference to the local Bluetooth adapter. * * @return Return true if the initialization is successful. */// w w w. j av a 2 s. c o m public boolean initialize() { // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManager == null) { EVLog.e("Unable to initialize BluetoothManager."); return false; } } mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { EVLog.e("Unable to obtain a BluetoothAdapter."); return false; } return true; }
From source file:com.nordicsemi.UART_UDP_PROXY.UartService.java
/** * Initializes a reference to the local Bluetooth adapter. * * @return Return true if the initialization is successful. *///from ww w. j av a2 s.co m public boolean initialize(MainActivity ui) { // DA this.m_ui = ui; // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManager == null) { Log.e(TAG, "Unable to initialize BluetoothManager."); return false; } } mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { Log.e(TAG, "Unable to obtain a BluetoothAdapter."); return false; } return true; }
From source file:com.huiwu.temperaturecontrol.bluetooth.BluetoothService.java
/** * Initializes a reference to the local Bluetooth adapter. * * @return Return true if the initialization is successful. */// ww w . jav a 2s .c o m public boolean initialize() { // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManager == null) { TestLog.e(TAG, "Unable to initialize BluetoothManager."); return false; } } mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { TestLog.e(TAG, "Unable to obtain a BluetoothAdapter."); return false; } return true; }
From source file:com.example.user.wase.view.fragment.EquipmentScanner.java
@Nullable @Override/* w w w .ja v a2 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.github.vgoliveira.panificadora.UartService.java
/** * Initializes a reference to the local Bluetooth adapter. * * @return Return true if the initialization is successful. */// w w w . ja v a 2 s. c o m public boolean initialize() { // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManager == null) { Log.e(TAG, "Unable to initialize BluetoothManager."); return false; } else { Log.e(TAG, "BluetoothManager initialized."); } } mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { Log.e(TAG, "Unable to obtain a BluetoothAdapter."); return false; } else { Log.e(TAG, "Abled to obtain a BluetoothAdapter."); } return true; }
From source file:com.android.car.trust.CarBleTrustAgent.java
private void maybeStartBleUnlockService() { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Trying to open a Ble GATT server"); }/* ww w . j a va2 s . c o m*/ BluetoothManager btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); BluetoothGattServer mGattServer = btManager.openGattServer(this, new BluetoothGattServerCallback() { @Override public void onConnectionStateChange(BluetoothDevice device, int status, int newState) { super.onConnectionStateChange(device, status, newState); } }); // The BLE stack is started up before the trust agent service, however Gatt capabilities // might not be ready just yet. Keep trying until a GattServer can open up before proceeding // to start the rest of the BLE services. if (mGattServer == null) { Log.e(TAG, "Gatt not available, will try again...in " + BLE_RETRY_MS + "ms"); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { maybeStartBleUnlockService(); } }, BLE_RETRY_MS); } else { mGattServer.close(); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "GATT available, starting up UnlockService"); } mCarUnlockService.start(); } }
From source file:kr.ac.kaist.resl.sensorservice.BluetoothService.java
@SuppressLint("HandlerLeak") @Override/*from w w w . j av 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.aprilbrother.blueduino.UartService.java
/** * Initializes a reference to the local Bluetooth adapter. * //from w w w .j a v a2 s. c o m * @return Return true if the initialization is successful. */ public boolean initialize() { // For API level 18 and above, get a reference to BluetoothAdapter // through // BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManager == null) { Log.e(TAG, "Unable to initialize BluetoothManager."); return false; } } mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { Log.e(TAG, "Unable to obtain a BluetoothAdapter."); return false; } return true; }
From source file:com.tkjelectronics.balanduino.BalanduinoActivity.java
@Override @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; context = getApplicationContext();/*from w w w . j a v a2 s. com*/ if (!getResources().getBoolean(R.bool.isTablet)) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Set portrait mode only - for small screens like phones else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); // Full screen rotation else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); // Full screen rotation new Handler().postDelayed(new Runnable() { // Hack to hide keyboard when the layout it rotated @Override public void run() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard - this is needed when the device is rotated imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0); } }, 1000); } setContentView(R.layout.activity_main); // Get local Bluetooth adapter if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); else mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { showToast("Bluetooth is not available", Toast.LENGTH_LONG); finish(); return; } // get sensorManager and initialize sensor listeners SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mSensorFusion = new SensorFusion(getApplicationContext(), mSensorManager); // Set up the action bar. final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayHomeAsUpEnabled(true); // Create the adapter that will return a fragment for each of the primary sections of the app. ViewPagerAdapter mViewPagerAdapter = new ViewPagerAdapter(getApplicationContext(), getSupportFragmentManager()); // Set up the ViewPager with the adapter. CustomViewPager mViewPager = (CustomViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mViewPagerAdapter); if (getResources().getBoolean(R.bool.isTablet)) mViewPager.setOffscreenPageLimit(2); // Since two fragments is selected in landscape mode, this is used to smooth things out // Bind the underline indicator to the adapter mUnderlinePageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator); mUnderlinePageIndicator.setViewPager(mViewPager); mUnderlinePageIndicator.setFades(false); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mUnderlinePageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (D) Log.d(TAG, "ViewPager position: " + position); if (position < actionBar.getTabCount()) // Needed for when in landscape mode actionBar.setSelectedNavigationItem(position); else mUnderlinePageIndicator.setCurrentItem(position - 1); } }); int count = mViewPagerAdapter.getCount(); Resources mResources = getResources(); boolean landscape = false; if (mResources.getBoolean(R.bool.isTablet) && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { landscape = true; count -= 1; // There is one less tab when in landscape mode } for (int i = 0; i < count; i++) { // For each of the sections in the app, add a tab to the action bar String text; if (landscape && i == count - 1) text = mViewPagerAdapter.getPageTitle(i) + " & " + mViewPagerAdapter.getPageTitle(i + 1); // Last tab in landscape mode have two titles in one tab else text = mViewPagerAdapter.getPageTitle(i).toString(); // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. actionBar.addTab(actionBar.newTab().setText(text).setTabListener(this)); } try { PackageManager mPackageManager = getPackageManager(); if (mPackageManager != null) BalanduinoActivity.appVersion = mPackageManager.getPackageInfo(getPackageName(), 0).versionName; // Read the app version name } catch (NameNotFoundException e) { e.printStackTrace(); } }
From source file:com.edutech.eBalanbot.eBalanbotActivity.java
@Override @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; context = getApplicationContext();//www . j a va 2 s .c om if (!getResources().getBoolean(R.bool.isTablet)) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Set portrait mode only - for small screens like phones else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); // Full screen rotation else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); // Full screen rotation new Handler().postDelayed(new Runnable() { // Hack to hide keyboard when the layout it rotated @Override public void run() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard - this is needed when the device is rotated imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0); } }, 1000); } setContentView(R.layout.activity_main); // Get local Bluetooth adapter if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); else mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { showToast("Bluetooth is not available", Toast.LENGTH_LONG); finish(); return; } // get sensorManager and initialize sensor listeners SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mSensorFusion = new SensorFusion(getApplicationContext(), mSensorManager); // Set up the action bar. final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayHomeAsUpEnabled(true); // Create the adapter that will return a fragment for each of the primary sections of the app. ViewPagerAdapter mViewPagerAdapter = new ViewPagerAdapter(getApplicationContext(), getSupportFragmentManager()); // Set up the ViewPager with the adapter. CustomViewPager mViewPager = (CustomViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mViewPagerAdapter); if (getResources().getBoolean(R.bool.isTablet)) mViewPager.setOffscreenPageLimit(2); // Since two fragments is selected in landscape mode, this is used to smooth things out // Bind the underline indicator to the adapter mUnderlinePageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator); mUnderlinePageIndicator.setViewPager(mViewPager); mUnderlinePageIndicator.setFades(false); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mUnderlinePageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (D) Log.d(TAG, "ViewPager position: " + position); if (position < actionBar.getTabCount()) // Needed for when in landscape mode actionBar.setSelectedNavigationItem(position); else mUnderlinePageIndicator.setCurrentItem(position - 1); } }); int count = mViewPagerAdapter.getCount(); Resources mResources = getResources(); boolean landscape = false; if (mResources.getBoolean(R.bool.isTablet) && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { landscape = true; count -= 1; // There is one less tab when in landscape mode } for (int i = 0; i < count; i++) { // For each of the sections in the app, add a tab to the action bar String text; if (landscape && i == count - 1) text = mViewPagerAdapter.getPageTitle(i) + " & " + mViewPagerAdapter.getPageTitle(i + 1); // Last tab in landscape mode have two titles in one tab else text = mViewPagerAdapter.getPageTitle(i).toString(); // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. actionBar.addTab(actionBar.newTab().setText(text).setTabListener(this)); } try { PackageManager mPackageManager = getPackageManager(); if (mPackageManager != null) eBalanbotActivity.appVersion = mPackageManager.getPackageInfo(getPackageName(), 0).versionName; // Read the app version name } catch (NameNotFoundException e) { e.printStackTrace(); } }