List of usage examples for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE
String ACTION_REQUEST_ENABLE
To view the source code for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE.
Click Source Link
From source file:org.libreoffice.impressremote.activity.ComputersActivity.java
@Override protected void onCreate(Bundle aSavedInstanceState) { super.onCreate(aSavedInstanceState); setContentView(R.layout.activity_computers); Toolbar toolbar = (Toolbar) findViewById(R.id.computers_toolbar); setSupportActionBar(toolbar);/* ww w . j a v a 2 s. c o m*/ // Looks hacky but it seems to be the best way to set activitys title // different to applications label. The other way is setting title // to intents filter but it shows wrong label for recent apps screen then. assert toolbar != null; toolbar.setTitle(R.string.title_computers); computersPagerAdapter.addFragment(Type.BLUETOOTH); computersPagerAdapter.addFragment(Type.WIFI); ViewPager aComputersPager = (ViewPager) findViewById(R.id.pager_computers); assert aComputersPager != null; aComputersPager.setAdapter(computersPagerAdapter); tabLayout = (TabLayout) findViewById(R.id.pager_computers_tabs); assert tabLayout != null; tabLayout.setupWithViewPager(aComputersPager); btTab = tabLayout.getTabAt(0); wifiTab = tabLayout.getTabAt(1); assert wifiTab != null; wifiTab.select(); if (btAdapter == null) { computersPagerAdapter.removeFragment(Type.BLUETOOTH); } tabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(aComputersPager) { @Override public void onTabSelected(TabLayout.Tab tab) { super.onTabSelected(tab); if (btAdapter != null && tab.getPosition() == btTab.getPosition() && !btAdapter.isEnabled()) { startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_ENABLE_BT); } } }); btFab = (FloatingActionButton) findViewById(R.id.btFab); btFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (btAdapter != null && btAdapter.startDiscovery()) { btFab.setClickable(false); // workaround, see https://code.google.com/p/android/issues/detail?id=175696#c6 // when not delayed animation won't show on pre-lollipop unless switching tabs btFab.postDelayed(new Runnable() { @Override public void run() { btFab.startAnimation(AnimationUtils.loadAnimation(getApplication(), R.anim.fabalpha)); } }, 50); } } }); addFab = (FloatingActionButton) findViewById(R.id.addFab); addFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getSupportFragmentManager().getFragments().get(0).startActivityForResult( Intents.buildComputerCreationIntent(tabLayout.getContext()), Intents.RequestCodes.CREATE_SERVER); } }); }
From source file:com.example.android.mdpandroid.Bluetooth.BluetoothChatFragment.java
@Override public void onStart() { super.onStart(); // If BT is not on, request that it be enabled. if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the chat session } else if (mChatService == null) { setupChat();//from ww w .j a v a 2 s.c o m } }
From source file:za.co.paulscott.antifitness.ModuleActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (!bluetoothManager.getAdapter().isEnabled()) { final Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); }/* w w w. j a v a2 s . c om*/ getApplicationContext().bindService(new Intent(this, MetaWearBLEService.class), this, Context.BIND_AUTO_CREATE); if (savedInstanceState != null) { device = (BluetoothDevice) savedInstanceState.getParcelable(EXTRA_BLE_DEVICE); moduleFragment = (ModuleFragment) getSupportFragmentManager().getFragment(savedInstanceState, "mContent"); } }
From source file:org.physical_web.physicalweb.MainActivity.java
/** * Ensures Bluetooth is available on the beacon and it is enabled. If not, * displays a dialog requesting user permission to enable Bluetooth. *//*from w w w.j ava 2s . com*/ private void checkPermissions(BluetoothAdapter bluetoothAdapter) { // Acquire lock PermissionCheck.getInstance().setCheckingPermissions(true); if (!bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); return; } ensureLocationPermissionIsEnabled(); }
From source file:edu.uwb.css.a545.project.socialplay.BluetoothChatFragment.java
@Override public void onStart() { super.onStart(); // If BT is not on, request that it be enabled. // setupChat() will then be called during onActivityResult if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the chat session // } else if (mChatService == null) { } else if (mServices.size() == 0) { setupChat();/*from w w w . java 2 s . c o m*/ } }
From source file:com.grandpaj.library2.bluetooth.BluetoothCommunication.java
public void startCommunication() { // If BT is not on, request that it be enabled. // setupChat() will then be called during onActivityResult if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the chat session } else if (mChatService == null) { setupChat();/*from w w w. ja v a 2s . c o m*/ } }
From source file:app.park.com.bluetooth.BluetoothFragment.java
@Override public void onStart() { super.onStart(); // If BT is not on, request that it be enabled. // setupBT() will then be called during onActivityResult if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the bt session } else if (mBTService == null) { setupBT();//from w w w . j a va 2 s .com } }
From source file:com.mikel.poseidon.Activities.preferences.BluetoothDeviceActivity.java
@Override protected void onResume() { super.onResume(); final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { mBluetoothAdapter = bluetoothManager.getAdapter(); }/*w w w . ja v a 2 s. c o m*/ if (!mBluetoothAdapter.isEnabled()) { if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, 1); } } mPairedDevice = mSettings.getString("macaddress", ""); if (!mPairedDevice.isEmpty()) { BluetoothDevice bluetoothDevice = new BluetoothDevice(); bluetoothDevice.macaddress = mPairedDevice; bluetoothDevice.name = "Currently not found"; bluetoothDevice.checked = true; bluetoothDevice.rssi = -1000; mFragment.foundDevice(bluetoothDevice); } }
From source file:com.github.matt.williams.blook8r.MapActivity.java
@Override protected void onResume() { super.onResume(); // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. if (!blook8r.start(this, this)) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); }//from ww w . ja v a 2 s .c om setUpMapIfNeeded(); Map<String, Beacon> beacons = blook8r.getBeacons(); for (Beacon beacon : beacons.values()) { LatLng point = new LatLng(beacon.location.y, beacon.location.x); mMap.addMarker(new MarkerOptions().position(point) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)) .title(beacon.name)); } }
From source file:com.bluetooth.comp529.bluetoothchatproj.chat.BluetoothChatFragment.java
@Override public void onStart() { // enable BlueTooth at onStart() super.onStart(); Log.d(TAG, "call onStart"); // If BT is not on, request that it be enabled. // setupChat() will then be called during onActivityResult if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the chat session } else if (mChatService == null) { Log.d(TAG, "mChatService is NULL"); setupChat();/*from www. ja v a 2 s .co m*/ } }