List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter
public static synchronized BluetoothAdapter getDefaultAdapter()
From source file:com.dipesan.miniatm.miniatm.services.BluetoothConnexionManager.java
private BluetoothConnexionManager() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (!adapter.isEnabled()) { adapter.enable(); } }
From source file:org.deviceconnect.android.deviceplugin.host.activity.BluetoothManageActivity.java
@Override protected void onStart() { super.onStart(); mRequestParam = new Bundle(getIntent().getExtras()); if (MessageUtils.getAttribute(getIntent()).equals(ConnectionProfile.ATTRIBUTE_BLUETOOTH)) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); try {/*from w w w .j a v a2 s .c o m*/ startActivityForResult(enableIntent, 0); } catch (ActivityNotFoundException e) { BluetoothAdapter.getDefaultAdapter().enable(); } } else if (MessageUtils.getAttribute(getIntent()).equals(ConnectionProfile.ATTRIBUTE_BLE)) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); try { startActivityForResult(enableIntent, 0); } catch (ActivityNotFoundException e) { BluetoothAdapter.getDefaultAdapter().enable(); } } else { // finish if attribute is unknown finish(); } }
From source file:com.dipesan.miniatm.miniatm.services.BluetoothConnexionManager.java
public boolean connect() { if (deviceAddr == null) { return false; }/* w ww.j ava 2s . c om*/ LogManager.debug(BluetoothConnexionManager.class.getSimpleName(), "connect to " + deviceAddr); if (socket != null && socket.isConnected()) { try { socket.close(); } catch (IOException ignored) { } } BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddr); try { // socket = device.createRfcommSocketToServiceRecord(BT_UUID); Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] { int.class }); socket = (BluetoothSocket) m.invoke(device, Integer.valueOf(1)); socket.connect(); RPCManager.getInstance().start(socket.getInputStream(), socket.getOutputStream()); return true; } catch (Exception e) { LogManager.debug(BluetoothConnexionManager.class.getName(), "connect device error", e); if (socket != null && socket.isConnected()) { try { socket.close(); } catch (IOException ignored) { } } return false; } }
From source file:shantanu.housemate.bluetoothchat.BluetoothActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bluetooth_main); //Disable bluetooth BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable();//from ww w .j av a 2s.c o m } Log.i("BLUETOOTH ACTIVITY", "STARTED"); if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); fragment = new BluetoothChatFragment(); transaction.replace(R.id.sample_content_fragment, fragment); transaction.commit(); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.ProfileObj.java
/** * Returns an Obj of type {@link #TYPE} with a profile representing * the local user. The profile is set with the given name and info fields. */// w w w . j a va2s . c om public static Obj forLocalUser(Context c, String name, String about) { JSONObject obj = new JSONObject(); try { obj.put("name", name); obj.put("about", about); // TODO: Framework. BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter != null) { UUID btUuid = ContentCorral.getLocalBluetoothServiceUuid(c); String btMac = btAdapter.getAddress(); obj.put(Contact.ATTR_BT_MAC, btMac); obj.put(Contact.ATTR_BT_CORRAL_UUID, btUuid.toString()); } obj.put(Contact.ATTR_PROTOCOL_VERSION, App.POSI_VERSION); } catch (JSONException e) { } return new MemObj(TYPE, obj); }
From source file:org.jonblack.bluetrack.activities.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); // Load default preference values. // The defaults are only loaded if they haven't been done before. It will // not overwrite changes. // @see PreferenceManager.setDefaultValues PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Get the local bluetooth adapter and check if bluetooth is supported. BluetoothAdapter localBtAdapter = BluetoothAdapter.getDefaultAdapter(); if (localBtAdapter == null) { Log.w(TAG, "Bluetooth isn't supported on device."); AlertDialog ad = new AlertDialog.Builder(this).create(); ad.setCancelable(false);/*from www . j a v a 2 s . c o m*/ Resources r = getResources(); String msg = r.getString(R.string.error_bluetooth_not_supported, r.getString(R.string.app_name)); ad.setMessage(msg); ad.setButton(AlertDialog.BUTTON_POSITIVE, r.getString(R.string.button_exit), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); dialog.dismiss(); } }); ad.show(); return; } Resources r = getResources(); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab tab1 = actionBar.newTab().setText(r.getText(R.string.ab_tab_live_tracking)); tab1.setTag("tracking"); tab1.setTabListener(new TabListener<LiveTrackingFragment>(this, "tracking", LiveTrackingFragment.class)); actionBar.addTab(tab1); ActionBar.Tab tab2 = actionBar.newTab().setText(r.getText(R.string.ab_tab_sessions)); tab2.setTag("session"); tab2.setTabListener(new TabListener<SessionFragment>(this, "session", SessionFragment.class)); actionBar.addTab(tab2); ActionBar.Tab tab3 = actionBar.newTab().setText(r.getText(R.string.ab_tab_devices)); tab3.setTag("devices"); tab3.setTabListener(new TabListener<DevicesFragment>(this, "devices", DevicesFragment.class)); actionBar.addTab(tab3); }
From source file:uk.ac.horizon.ubihelper.service.channel.BluetoothDiscoveryChannel.java
/** * @param handler/*from w w w .jav a 2 s .com*/ * @param name */ public BluetoothDiscoveryChannel(Service service, Handler handler, String name) { super(handler, name); bluetooth = BluetoothAdapter.getDefaultAdapter(); this.service = service; if (bluetooth == null) Log.w(TAG, "No BluetoothAdapter"); if (!bluetooth.isEnabled()) { Intent i = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); service.sendBroadcast(i); } IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(BluetoothDevice.ACTION_FOUND); filter.addAction(BluetoothDevice.ACTION_NAME_CHANGED); this.service.registerReceiver(receiver, filter); }
From source file:com.sweetiepiggy.littlepro.LittleProActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_littlepro); mBluetoothHandler = new BluetoothHandler(); mBluetoothHelper = new BluetoothHelper(BluetoothAdapter.getDefaultAdapter(), mBluetoothHandler); mQuestionsPagerAdapter = new QuestionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mQuestionsPagerAdapter); // List<QuestionFragment> questionFragments = new ArrayList<QuestionFragment>(); // questionFragments.add(QuestionFragment.newInstance("What does 2+2 equal?")); // questionFragments.add(QuestionFragment.newInstance("What is 25x10?")); // questionFragments.add(QuestionFragment.newInstance("Calculate 503-24.")); // mQuestionsPagerAdapter.setQuestionFragments(questionFragments); }
From source file:com.thiagorosa.robotita.manager.BluetoothManager.java
/******************************************************************************************* *******************************************************************************************/ public BluetoothAdapter getAdapter() { return BluetoothAdapter.getDefaultAdapter(); }
From source file:io.v.positioning.BluetoothPositionActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bluetoothposition); Button scanButton = (Button) findViewById(R.id.button_scan); scanButton.setOnClickListener(new View.OnClickListener() { @Override//from w w w .j av a 2 s .co m public void onClick(View v) { doDiscovery(); v.setVisibility(View.GONE); } }); mRecordedDevices = new ArrayAdapter<String>(this, R.layout.device_name); ListView recordedDevicesListView = (ListView) findViewById(R.id.recorded_devices); recordedDevicesListView.setAdapter(mRecordedDevices); this.registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND)); this.registerReceiver(mReceiver, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)); mBtAdapter = BluetoothAdapter.getDefaultAdapter(); }