List of usage examples for android.bluetooth BluetoothAdapter isEnabled
@RequiresPermission(Manifest.permission.BLUETOOTH) public boolean isEnabled()
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();/*from w w w. ja v a 2s . com*/ scanAndConnectToLastConnectedMeme(); } } }
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent == null) { return START_STICKY; }//from www. j a v a 2 s .c om String action = intent.getAction(); if (Intent.ACTION_BATTERY_CHANGED.equals(action) || Intent.ACTION_BATTERY_LOW.equals(action) || Intent.ACTION_BATTERY_OKAY.equals(action)) { // ???? mHostBatteryManager.setBatteryRequest(intent); List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostBatteryProfile.PROFILE_NAME, null, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostBatteryProfile.setAttribute(mIntent, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE); Bundle battery = new Bundle(); HostBatteryProfile.setLevel(battery, mHostBatteryManager.getBatteryLevel()); getContext().sendBroadcast(mIntent); } return START_STICKY; } else if (Intent.ACTION_POWER_CONNECTED.equals(action) || Intent.ACTION_POWER_DISCONNECTED.equals(action)) { // ???? mHostBatteryManager.setBatteryRequest(intent); List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostBatteryProfile.PROFILE_NAME, null, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostBatteryProfile.setAttribute(mIntent, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE); Bundle charging = new Bundle(); if (Intent.ACTION_POWER_CONNECTED.equals(action)) { HostBatteryProfile.setCharging(charging, true); } else { HostBatteryProfile.setCharging(charging, false); } HostBatteryProfile.setBattery(mIntent, charging); getContext().sendBroadcast(mIntent); } return START_STICKY; } else if (action.equals("android.intent.action.NEW_OUTGOING_CALL")) { // Phone List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostPhoneProfile.PROFILE_NAME, null, HostPhoneProfile.ATTRIBUTE_ON_CONNECT); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostPhoneProfile.setAttribute(mIntent, HostPhoneProfile.ATTRIBUTE_ON_CONNECT); Bundle phoneStatus = new Bundle(); HostPhoneProfile.setPhoneNumber(phoneStatus, intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER)); HostPhoneProfile.setState(phoneStatus, CallState.START); HostPhoneProfile.setPhoneStatus(mIntent, phoneStatus); getContext().sendBroadcast(mIntent); } return START_STICKY; } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action) || WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { // Wifi List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostConnectProfile.PROFILE_NAME, null, HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE); Bundle wifiConnecting = new Bundle(); WifiManager wifiMgr = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); HostConnectProfile.setEnable(wifiConnecting, wifiMgr.isWifiEnabled()); HostConnectProfile.setConnectStatus(mIntent, wifiConnecting); getContext().sendBroadcast(mIntent); } return START_STICKY; } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostConnectProfile.PROFILE_NAME, null, HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE); Bundle bluetoothConnecting = new Bundle(); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); HostConnectProfile.setEnable(bluetoothConnecting, mBluetoothAdapter.isEnabled()); HostConnectProfile.setConnectStatus(mIntent, bluetoothConnecting); getContext().sendBroadcast(mIntent); } return START_STICKY; } return super.onStartCommand(intent, flags, startId); }
From source file:ua.mkh.settings.full.MainActivity.java
private void ButtonTextBth() { if (bt != null) { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); TextView textbt = (TextView) findViewById(R.id.textbt); if (mBluetoothAdapter.isEnabled()) textbt.setText(R.string.on); else//w w w.j a v a 2 s. co m textbt.setText(R.string.off); } }
From source file:com.plusot.senselib.SenseMain.java
@SuppressWarnings("deprecation") public void showPopupDialog(int dialogId, int viewId, String[] items) {// , if (!alive) { if (dialogId == STEP_POPUP) popupToShow = STEP_POPUP;//from ww w .ja v a 2 s . c o m return; } int iEnd = 3; int timeOut = 0; int defaultChoice = 0; boolean cancelable = true; popupToShow = -1; String title = null; Map<String, String> lookup = null; if (items == null) items = getResources().getStringArray(R.array.value_popup_dialog_items); switch (dialogId) { case VALUE_POPUP: title = getString(R.string.valuepopup); items = getResources().getStringArray(R.array.value_popup_dialog_items); if (viewHasValue(viewId)) { popupValue = viewGetCurrentValue(viewId); title = popupValue.getValueType(this); if (popupValue.getValueType().equals(ValueType.POWER)) { items = Arrays.copyOf(items, items.length + 1); items[items.length - 1] = getString(R.string.calibrate); } else if (popupValue.getValueType().equals(ValueType.SLOPE)) { items = Arrays.copyOf(items, items.length + 1); items[items.length - 1] = getString(R.string.set_level); } } break; case VALUESELECT_POPUP: title = getString(R.string.valuepopup); items = Value.getValuePopupList(this, PreferenceKey.XTRAVALUES.isTrue()); break; case UNIT_POPUP: title = getString(R.string.unitpopup); if (items == null || items.length == 0) ToastHelper.showToastLong(R.string.no_unit_choice); break; case YEAR_POPUP: title = getString(R.string.yearpopup); if (fileExplorer == null) { items = null; } else { items = fileExplorer.getYears(); } if (items == null || items.length == 0) { ToastHelper.showToastLong(R.string.no_year_choice); return; } else if (items.length > 1) { break; } logYear = items[0]; dialogId = MONTH_POPUP; case MONTH_POPUP: title = getString(R.string.monthpopup); if (fileExplorer == null) { items = null; } else { logMonths = fileExplorer.getMonths(logYear); items = FileExplorer.getMonths(logYear, logMonths); } if (items == null || items.length == 0) { ToastHelper.showToastLong(getString(R.string.no_month_choice, logYear)); return; } else if (items.length > 1) { break; } logMonth = logMonths[0]; LLog.d(Globals.TAG, CLASSTAG + ".showPopupDialog: logMonth = " + logMonth); dialogId = DAY_POPUP; case DAY_POPUP: title = getString(R.string.daypopup); if (fileExplorer == null) { items = null; } else { logDays = fileExplorer.getDays(logYear, logMonth); items = FileExplorer.getDays(logYear, DateUtils.getMonthString(logMonth - 1, DateUtils.LENGTH_LONG), logDays); } break; case TIMES_POPUP: title = getString(R.string.timespopup); if (fileExplorer == null) { items = null; } else { items = fileExplorer.getTimes(logYear, logMonth, logDay); } break; case MOVESTART_POPUP: lastAskForActivityStart = System.currentTimeMillis(); if (moveStartBusy) { title = null; } else { moveStartBusy = true; title = getString(R.string.movestartpopup); items = getResources().getStringArray(R.array.start_popup_dialog_items); if (SenseGlobals.stopState.equals(SenseGlobals.StopState.STOP)) items = Arrays.copyOfRange(items, 1, iEnd); else items = Arrays.copyOfRange(items, 0, iEnd); cancelable = false; } break; case STEP_POPUP: lastAskForActivityStart = System.currentTimeMillis(); timeOut = 10000; switch (step) { case 0: title = getString(R.string.recoverypopup); items = getResources().getStringArray(R.array.fitnessorrecovery_popup_dialog_items); cancelable = false; break; case 1: title = getString(R.string.step1settingspopup); List<String> list = new ArrayList<String>(); String profile = PreferenceKey.getProfileName(); list.add(getString(R.string.step1_bikeprofile, profile)); //list.add(getString(R.string.popitem_wheelcirumference, prefs.getWheelCirc())); if (PreferenceKey.USEPAIRING.isTrue()) list.add(getString(R.string.popitem_pairing_on, profile)); else list.add(getString(R.string.popitem_pairing_off, profile)); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null && adapter.isEnabled()) list.add(getString(R.string.popitem_bluetooth_on)); else list.add(getString(R.string.popitem_bluetooth_off)); list.add(getString(R.string.step_continue)); items = list.toArray(new String[0]); cancelable = false; break; case 2: if (PreferenceKey.XTRAVALUES.isTrue()) { title = getString(R.string.startpopup); iEnd = 3; } else { title = getString(R.string.step2startpopup); iEnd = 4; } cancelable = false; if (title == null) title = getString(R.string.startpopup); items = getResources().getStringArray(R.array.start_popup_dialog_items); if (SenseGlobals.stopState.equals(SenseGlobals.StopState.STOP)) { items = Arrays.copyOfRange(items, 1, iEnd); startOptions = 3; } else { items = Arrays.copyOfRange(items, 0, iEnd); startOptions = 4; } break; } break; case START_POPUP: lastAskForActivityStart = System.currentTimeMillis(); if (title == null) title = getString(R.string.startpopup); timeOut = 10000; items = getResources().getStringArray(R.array.start_popup_dialog_items); if (SenseGlobals.stopState.equals(SenseGlobals.StopState.STOP)) items = Arrays.copyOfRange(items, 1, iEnd); else items = Arrays.copyOfRange(items, 0, iEnd); break; case ARGOSSTOP_POPUP: cancelable = false; switch (argosStopStep) { case 0: title = getString(R.string.intensitypopup); items = getResources().getStringArray(R.array.intensity_popup_dialog_items); break; case 1: title = getString(R.string.fitnesspopup); items = getResources().getStringArray(R.array.fitnessorrecovery_popup_dialog_items); break; } break; case FULLSTOP_POPUP: lastAskForActivityStart = System.currentTimeMillis(); title = getString(R.string.stoppopup); items = getResources().getStringArray(R.array.stop_popup_dialog_items); break; case STOP_POPUP: lastAskForActivityStart = System.currentTimeMillis(); title = getString(R.string.stoppopup); items = getResources().getStringArray(R.array.stop_popup_dialog_items); break; case SHARE_POPUP: title = getString(R.string.sharepopup); items = getResources().getStringArray(R.array.share_popup_dialog_items); if (Globals.testing.isNoTest()) items = Arrays.copyOf(items, items.length - 1); break; case INTERVAL_POPUP: title = getString(R.string.menu_interval); items = getResources().getStringArray(R.array.interval_popup_dialog_items); break; case GPX_POPUP: title = getString(R.string.menu_gpx); FileExplorer.FileList list = FileExplorer.getFileList( new String[] { Globals.getDataPath(), Globals.getDownloadPath(), SenseGlobals.getGpxPath() }, new String[] { ".gpx" }, false); items = list.items; lookup = list.lookup; break; } if (title != null && items != null && items.length > 0) { if (!PopupDialog.showPopupDialog(getFragmentManager(), title, dialogId, viewId, items, lookup, cancelable, timeOut, defaultChoice) && dialogId == STEP_POPUP) popupToShow = STEP_POPUP; } }