List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter
public static synchronized BluetoothAdapter getDefaultAdapter()
From source file:com.manuelmazzuola.speedtogglebluetooth.service.MonitorSpeed.java
@Override public void onLocationChanged(Location location) { float distance = (oldLocation.distanceTo(location) - location.getAccuracy()); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (location.getAccuracy() > 0.0f) if (distance > triggerDistance && !activated && !disabled) { bluetoothAdapter.enable();/* w w w . ja v a2 s . c o m*/ activated = true; changeMessage(WAITING_MESSAGE); starTimer(); } else if (disabled && distance < triggerDistance) { if (++counter > 1) { disabled = false; changeMessage(DEFAULT_MESSAGE); } } oldLocation = location; }
From source file:com.example.android.bluetoothchat.MainActivityCustom.java
/** * Overridden methods//w ww .j av a 2s . c o m */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); } textData = (TextView) findViewById(R.id.data_text); Button buttonScan = (Button) findViewById(R.id.button_scan_c); buttonScan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Launch the DeviceListActivity to see devices and do scan Intent serverIntent = new Intent(MainActivityCustom.this, DeviceListActivity.class); startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE); } }); // MO // Initialize the send wallets button with a listener that for click events Button mSendWalletsButton = (Button) findViewById(R.id.button_send_wallets); mSendWalletsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Send a message using content of the edit text widget AccountItem accountItem = AccountItem.createDummyAccount(); Gson gson = new Gson(); String json = gson.toJson(accountItem); sendMessage(json); mChatService.disconnect(); } }); Button buttonFinish = (Button) findViewById(R.id.button_finish); buttonFinish.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainActivityCustom.this.finish(); } }); }
From source file:com.bruce.study.demo.github.bluetooth_demo1.HelpFragment.java
public void startbt() { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { mkmsg("????"); return;//from ww w.jav a 2 s .co m } if (!mBluetoothAdapter.isEnabled()) { mkmsg("??"); Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivity(enableIntent); } else { mkmsg("??"); querypaired(); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.ProfileObj.java
public static Obj getLocalProperties(Context c) { JSONObject obj = new JSONObject(); try {//from w w w . j av a 2s . c o m // 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("userAttributes", obj); }
From source file:com.duy.pascal.interperter.libraries.android.connection.bluetooth.AndroidBluetoothLib.java
public AndroidBluetoothLib(AndroidLibraryManager manager) { mAndroidFacade = manager.getReceiver(AndroidUtilsLib.class); mBluetoothAdapter = MainThread.run(manager.getContext(), new Callable<BluetoothAdapter>() { @Override/* w ww .j a v a2 s . com*/ public BluetoothAdapter call() throws Exception { return BluetoothAdapter.getDefaultAdapter(); } }); }
From source file:com.googlecode.android_scripting.facade.BluetoothFacade.java
public BluetoothFacade(FacadeManager manager) { super(manager); mAndroidFacade = manager.getReceiver(AndroidFacade.class); mBluetoothAdapter = MainThread.run(manager.getService(), new Callable<BluetoothAdapter>() { @Override/* www . j a va 2 s. c o m*/ public BluetoothAdapter call() throws Exception { return BluetoothAdapter.getDefaultAdapter(); } }); }
From source file:uk.co.ivaylokhr.crawl.Controller.BluetoothController.java
/** * @param savedInstanceState//from ww w . jav a 2 s .c o m */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); // Get local Bluetooth adapter connected = false; mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { FragmentActivity activity = getActivity(); Toast.makeText(activity, "Bluetooth is not available", Toast.LENGTH_LONG).show(); } }
From source file:com.anand.bluetoothsample.BluetoothChatFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setHasOptionsMenu(true); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { FragmentActivity activity = getActivity(); Toast.makeText(activity, "Bluetooth is not available", Toast.LENGTH_LONG).show(); activity.finish();/*w w w .j a v a2s .c o m*/ } }
From source file:de.schildbach.wallet.offline.AcceptBluetoothService.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); this.application = (WalletApplication) getApplication(); final BluetoothAdapter bluetoothAdapter = checkNotNull(BluetoothAdapter.getDefaultAdapter()); final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); wakeLock.acquire();//from w w w . j ava 2 s.c o m registerReceiver(bluetoothStateChangeReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); try { classicThread = new AcceptBluetoothThread.ClassicBluetoothThread(bluetoothAdapter) { @Override public boolean handleTx(final Transaction tx) { return AcceptBluetoothService.this.handleTx(tx); } }; paymentProtocolThread = new AcceptBluetoothThread.PaymentProtocolThread(bluetoothAdapter) { @Override public boolean handleTx(final Transaction tx) { return AcceptBluetoothService.this.handleTx(tx); } }; } catch (final IOException x) { new Toast(this).longToast(R.string.error_bluetooth, x.getMessage()); log.warn("problem with listening, stopping service", x); CrashReporter.saveBackgroundTrace(x, application.packageInfo()); stopSelf(); } wallet = new WalletLiveData(application); wallet.observe(this, new Observer<Wallet>() { @Override public void onChanged(final Wallet wallet) { classicThread.start(); paymentProtocolThread.start(); } }); }
From source file:com.notalenthack.blaster.BluetoothSerialService.java
/** * Constructor. Prepares a new BluetoothChat session. * @param context The UI Activity Context * @param handler A Handler to send messages back to the UI Activity *///from ww w. j ava 2s . com public BluetoothSerialService(Context context, Handler handler) { mAdapter = BluetoothAdapter.getDefaultAdapter(); mState = STATE_NONE; mHandler = handler; mContext = context; mAllowInsecureConnections = false; }