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:com.teeptrak.controller.MainActivity.java
@Override public void onResume() { super.onResume(); Log.d(TAG, "onResume"); DfuServiceListenerHelper.registerProgressListener(this, mProgressBarListener); if (!mBtAdapter.isEnabled()) { Log.i(TAG, "onResume - BT not enabled yet"); Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); }/*from w ww .jav a2s . c o m*/ }
From source file:com.jins_meme.bridge.MainActivity.java
private void checkBluetoothEnable() { if (!isMemeConnected()) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, 0); } else if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { Log.d("DEBUG", "MAIN:: Initialize MEME LIB"); initMemeLib();/*w w w.ja va 2s . com*/ scanAndConnectToLastConnectedMeme(); } } }
From source file:net.emilymaier.movebot.MoveBotActivity.java
@Override @SuppressWarnings({ "deprecation", "unchecked" }) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from ww w . jav a2 s . co m*/ PreferenceManager.setDefaultValues(this, R.xml.preferences, false); Units.initialize(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); runs = new ArrayList<>(); try { FileInputStream fis = openFileInput("runs.ser"); ObjectInputStream ois = new ObjectInputStream(fis); runs = (ArrayList<Run>) ois.readObject(); ois.close(); fis.close(); } catch (FileNotFoundException e) { } catch (IOException e) { throw new RuntimeException("IOException", e); } catch (ClassNotFoundException e) { throw new RuntimeException("ClassNotFoundException", e); } font = Typeface.createFromAsset(getAssets(), "fonts/led_real.ttf"); pager = (ViewPager) findViewById(R.id.pager); adapter = new MainPagerAdapter(getSupportFragmentManager()); runsFragment = new RunsFragment(); heartFragment = new HeartFragment(this); developerFragment = new DeveloperFragment(); controlFragment = new ControlFragment(); mapFragment = SupportMapFragment.newInstance(); pager.setAdapter(adapter); updateDeveloperMode(); gpsInfoTimer = new Timer(); gpsInfoTimer.schedule(new GpsInfoTask(), 2 * 1000); mapFragment.getMapAsync(this); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { if (!bluetoothAdapter.isEnabled()) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, 1); } } }
From source file:de.dmarcini.bt.homelight.HomeLightMainActivity.java
@Override protected void onResume() { super.onResume(); if (BuildConfig.DEBUG) { Log.v(TAG, "onResume()"); }/* www . j av a 2 s .co m*/ // // Systemeinstellungen einlesen // HomeLightSysConfig.readSysPrefs(getResources(), PreferenceManager.getDefaultSharedPreferences(this)); // // Stelle sicher, dass der BT Adapter aktiviert wurde // erzeuge einen Intend (eine Absicht) und schicke diese an das System // if (!btConfig.getBluethoothAdapter().isEnabled()) { // // erzeuge die Nachricht ans System, der "Rest" ist dann bei onActivityResult // Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, ProjectConst.REQUEST_ENABLE_BT); } else { // // versuche zu verbinden (wenn das was zu verbinden ist) // tryReconnectToDevice(); } }
From source file:com.kncwallet.wallet.ui.SendCoinsFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.send_coins_fragment, container, false); contactsListView = (ListView) view.findViewById(R.id.send_coins_contacts_list); viewBalanceBtc = (CurrencyTextView) view.findViewById(R.id.wallet_balance_btc); txText = (EditText) view.findViewById(R.id.send_coins_text); viewBalanceLocal = (CurrencyTextView) view.findViewById(R.id.wallet_balance_local); viewBalanceLocal.setPrecision(Constants.LOCAL_PRECISION, 0); viewBalanceLocal.setStrikeThru(Constants.TEST); viewBalanceBtc.setOnClickListener(new OnClickListener() { @Override//from w w w.ja va2 s . c o m public void onClick(final View v) { SendCoinsFragment.this.switchBalance(); } }); viewBalanceLocal.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { SendCoinsFragment.this.switchBalance(); } }); receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address); receivingAddressView.setAdapter(new AutoCompleteAddressAdapter(activity, null)); receivingAddressView.setOnFocusChangeListener(receivingAddressListener); receivingAddressView.addTextChangedListener(receivingAddressListener); receivingStaticView = view.findViewById(R.id.send_coins_receiving_static); receivingStaticAddressView = (TextView) view.findViewById(R.id.send_coins_receiving_static_address); receivingStaticLabelView = (TextView) view.findViewById(R.id.send_coins_receiving_static_label); receivingStaticView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus) { startReceivingAddressActionMode(); } else { clearActionMode(); } } }); btcAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount_btc); btcAmountView.setCurrencySymbol(DenominationUtil.getCurrencyCode(btcShift)); btcAmountView.setInputPrecision(DenominationUtil.getMaxPrecision(btcShift)); btcAmountView.setHintPrecision(btcPrecision); btcAmountView.setShift(btcShift); final CurrencyAmountView localAmountView = (CurrencyAmountView) view .findViewById(R.id.send_coins_amount_local); localAmountView.setInputPrecision(Constants.LOCAL_PRECISION); localAmountView.setHintPrecision(Constants.LOCAL_PRECISION); amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView); bluetoothEnableView = (CheckBox) view.findViewById(R.id.send_coins_bluetooth_enable); bluetoothEnableView.setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled()); bluetoothEnableView.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { if (isChecked && !bluetoothAdapter.isEnabled()) { // try to enable bluetooth startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_ENABLE_BLUETOOTH); } } }); bluetoothMessageView = (TextView) view.findViewById(R.id.send_coins_bluetooth_message); sentTransactionView = (ListView) view.findViewById(R.id.send_coins_sent_transaction); sentTransactionListAdapter = new TransactionsListAdapter(activity, wallet, application.maxConnectedPeers(), false); sentTransactionView.setAdapter(sentTransactionListAdapter); viewGo = (Button) view.findViewById(R.id.send_coins_go); viewGo.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { validateReceivingAddress(true); validateAmounts(true); if (everythingValid()) handleGo(); } }); if (savedInstanceState != null) { restoreInstanceState(savedInstanceState); } else { final Intent intent = activity.getIntent(); final String action = intent.getAction(); final Uri intentUri = intent.getData(); final String scheme = intentUri != null ? intentUri.getScheme() : null; if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && intentUri != null && "bitcoin".equals(scheme)) initStateFromBitcoinUri(intentUri); else if (intent.hasExtra(SendCoinsFragment.INTENT_EXTRA_ADDRESS)) initStateFromIntentExtras(intent.getExtras()); } TextView header = ((TextView) view.findViewById(R.id.header_text)); header.setText(R.string.send_heading); contactListAdapter = new SimpleCursorAdapter(activity, R.layout.address_book_row_small, null, new String[] { AddressBookProvider.KEY_ADDRESS, AddressBookProvider.KEY_LABEL, AddressBookProvider.KEY_ADDRESS, AddressBookProvider.KEY_ADDRESS }, new int[] { R.id.address_book_contact_image, R.id.address_book_row_label, R.id.address_book_row_address, R.id.address_book_row_source_image }); contactListAdapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) { if (view.getId() == R.id.address_book_contact_image) { //... SmartImageView img = (SmartImageView) view; //img.setImageBitmap(bm); String address = cursor.getString(columnIndex); Bitmap contactImage = AddressBookProvider.bitmapForAddress(SendCoinsFragment.this.getActivity(), address); if (contactImage != null) { img.setImageBitmap(contactImage); } else { String imageUrl = ContactImage.getImageUrl(activity, AddressBookProvider.resolveRowId(activity, address)); if (imageUrl != null) { img.setImageUrl(imageUrl, R.drawable.contact_placeholder); } else { img.setImageResource(R.drawable.contact_placeholder); } } return true; //true because the data was bound to the view } else if (view.getId() == R.id.address_book_row_source_image) { ((ImageView) view).setImageResource(cachedSourceImageResource(cursor.getString(columnIndex))); return true; } //Constants.ADDRESS_FORMAT_LINE_SIZE)); return false; } }); boolean smallScreen = getResources().getBoolean(R.bool.values_small); if (!smallScreen) { ListView list = (ListView) contactsListView; Drawable divider = getResources().getDrawable(R.drawable.transaction_list_divider); list.setDivider(divider); list.setDividerHeight(1); list.setAdapter(contactListAdapter); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //to save a lookup TextView addr = (TextView) view.findViewById(R.id.address_book_row_address); TextView label = (TextView) view.findViewById(R.id.address_book_row_label); if (setSendAddress(addr.getText().toString(), label.getText().toString())) { startReceivingAddressActionMode(); } else { informInvalidAddress(addr.getText().toString(), label.getText().toString()); } } }); } else { contactsListView.setVisibility(View.GONE); } return view; }
From source file:org.hopestarter.wallet.ui.send.SendCoinsFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.send_coins_fragment, container); payeeGroup = view.findViewById(R.id.send_coins_payee_group); payeeNameView = (TextView) view.findViewById(R.id.send_coins_payee_name); payeeVerifiedByView = (TextView) view.findViewById(R.id.send_coins_payee_verified_by); receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address); receivingAddressViewAdapter = new ReceivingAddressViewAdapter(activity); receivingAddressView.setAdapter(receivingAddressViewAdapter); receivingAddressView.setOnFocusChangeListener(receivingAddressListener); receivingAddressView.addTextChangedListener(receivingAddressListener); receivingStaticView = view.findViewById(R.id.send_coins_receiving_static); receivingStaticAddressView = (TextView) view.findViewById(R.id.send_coins_receiving_static_address); receivingStaticLabelView = (TextView) view.findViewById(R.id.send_coins_receiving_static_label); amountGroup = view.findViewById(R.id.send_coins_amount_group); final CurrencyAmountView btcAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount_btc); btcAmountView.setCurrencySymbol(config.getFormat().code()); btcAmountView.setInputFormat(config.getMaxPrecisionFormat()); btcAmountView.setHintFormat(config.getFormat()); final CurrencyAmountView localAmountView = (CurrencyAmountView) view .findViewById(R.id.send_coins_amount_local); localAmountView.setInputFormat(Constants.LOCAL_FORMAT); localAmountView.setHintFormat(Constants.LOCAL_FORMAT); amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView); amountCalculatorLink.setExchangeDirection(config.getLastExchangeDirection()); directPaymentEnableView = (CheckBox) view.findViewById(R.id.send_coins_direct_payment_enable); directPaymentEnableView.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override//from www . j av a2s . c o m public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { if (paymentIntent.isBluetoothPaymentUrl() && isChecked && !bluetoothAdapter.isEnabled()) { // ask for permission to enable bluetooth startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_ENABLE_BLUETOOTH_FOR_DIRECT_PAYMENT); } } }); hintView = (TextView) view.findViewById(R.id.send_coins_hint); directPaymentMessageView = (TextView) view.findViewById(R.id.send_coins_direct_payment_message); sentTransactionView = (FrameLayout) view.findViewById(R.id.send_coins_sent_transaction); sentTransactionAdapter = new TransactionsAdapter(activity, wallet, false, application.maxConnectedPeers(), null); sentTransactionViewHolder = sentTransactionAdapter.createTransactionViewHolder(sentTransactionView); sentTransactionView.addView(sentTransactionViewHolder.itemView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); privateKeyPasswordViewGroup = view.findViewById(R.id.send_coins_private_key_password_group); privateKeyPasswordView = (EditText) view.findViewById(R.id.send_coins_private_key_password); privateKeyBadPasswordView = view.findViewById(R.id.send_coins_private_key_bad_password); changeTransactionFeeView = (TextView) view.findViewById(R.id.change_transaction_fee_link); changeTransactionFeeView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showFeeSelectionDialog(); } }); return view; }
From source file:com.filterdevice.ProfileScanningFragment.java
public boolean checkBluetoothStatus() { /**/* w ww.j av a 2s. co m*/ * Ensures Blue tooth is enabled on the device. If Blue tooth is not * currently enabled, fire an intent to display a dialog asking the user * to grant permission to enable it. */ if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); return false; } return true; }
From source file:com.coinblesk.client.utils.UIUtils.java
private static void enableBluetooth(Activity activity) { if (!isBluetoothEnabled(activity)) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, 1); Intent exchangeRateChanged = new Intent(Constants.EXCHANGE_RATE_CHANGED_ACTION); LocalBroadcastManager.getInstance(activity).sendBroadcast(exchangeRateChanged); }//from ww w . j ava 2 s . c o m }
From source file:nl.dobots.presence.PresenceDetectionApp.java
@Override public void onEvent(EventListener.Event event) { switch (event) { case BLUETOOTH_INITIALIZED: { // if BLE init succeeded clear the notification again _notificationManager.cancel(Config.PRESENCE_NOTIFICATION_ID); break;//from w w w . j a v a 2 s . c om } case BLUETOOTH_TURNED_OFF: { if (_settings.isNotificationsEnabled()) { Intent contentIntent = new Intent(this, MainActivity.class); PendingIntent piContent = PendingIntent.getActivity(this, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent btEnableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); PendingIntent piBtEnable = PendingIntent.getActivity(this, 0, btEnableIntent, PendingIntent.FLAG_UPDATE_CURRENT); String errorMessage = "Can't detect presence without BLE!"; NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Presence Detection Error") .setContentText(errorMessage) .setStyle(new NotificationCompat.BigTextStyle().bigText(errorMessage)) .addAction(android.R.drawable.ic_menu_manage, "Enable Bluetooth", piBtEnable) .setContentIntent(piContent).setDefaults(Notification.DEFAULT_SOUND) .setLights(Color.BLUE, 500, 1000); _notificationManager.notify(Config.PRESENCE_NOTIFICATION_ID, builder.build()); } } } }
From source file:obdii.starter.automotive.iot.ibm.com.iot4a_obdii.Home.java
private void runRealObdBluetoothScan(final int obd_timeout_ms, final ObdProtocols obd_protocol) { if (!obdBridgeBluetooth.isBluetoothEnabled()) { final Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBluetooth, BLUETOOTH_REQUEST); return;//from w w w.ja v a 2 s.c o m } final Set<BluetoothDevice> pairedDevicesSet = obdBridgeBluetooth.getPairedDeviceSet(); // In case user clicks on Change Network, need to repopulate the devices list final ArrayList<String> deviceNames = new ArrayList<>(); final ArrayList<String> deviceAddresses = new ArrayList<>(); if (pairedDevicesSet != null && pairedDevicesSet.size() > 0) { for (BluetoothDevice device : pairedDevicesSet) { deviceNames.add(device.getName()); deviceAddresses.add(device.getAddress()); } final String preferredName = getPreference(SettingsFragment.BLUETOOTH_DEVICE_NAME, "obd").toLowerCase(); final AlertDialog.Builder alertDialog = new AlertDialog.Builder(Home.this, R.style.AppCompatAlertDialogStyle); final ArrayAdapter adapter = new ArrayAdapter(Home.this, android.R.layout.select_dialog_singlechoice, deviceNames.toArray(new String[deviceNames.size()])); int selectedDevice = -1; for (int i = 0; i < deviceNames.size(); i++) { if (deviceNames.get(i).toLowerCase().contains(preferredName)) { selectedDevice = i; } } alertDialog.setCancelable(false).setSingleChoiceItems(adapter, selectedDevice, null) .setTitle("Please Choose the OBDII Bluetooth Device") .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); final int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); final String deviceAddress = deviceAddresses.get(position); final String deviceName = deviceNames.get(position); startConnectingBluetoothDevice(deviceAddress, deviceName, obd_timeout_ms, obd_protocol); setPreference(SettingsFragment.BLUETOOTH_DEVICE_NAME, deviceName); } }).show(); } else { Toast.makeText(getApplicationContext(), "Please pair with your OBDII device and restart the application!", Toast.LENGTH_SHORT).show(); } }