Example usage for android.bluetooth BluetoothAdapter getDefaultAdapter

List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter getDefaultAdapter.

Prototype

public static synchronized BluetoothAdapter getDefaultAdapter() 

Source Link

Document

Get a handle to the default local Bluetooth adapter.

Usage

From source file:com.molidt.easyandroid.bluetooth.BluetoothFragmentV4.java

protected void initPlugin(Activity activity) {
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    _activity = activity;/*from   w  w w .ja va 2  s . c om*/
    if (mBluetoothAdapter == null) {
        isSupportBluetooth = false;
        isSupportBLE = false;
    } else {
        isSupportBluetooth = true;
        if (_activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
            isSupportBLE = true;
        } else {
            isSupportBLE = false;
        }
    }
    isInit = true;
}

From source file:org.da_cha.android.bluegnss.MainFragment.java

private void setBluetoothDeviceName(View v) {
    Log.v(LOG_TAG, "entered setBluetoothDeviceName()");
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    String deviceAddress = sharedPref.getString(GnssProviderService.PREF_BLUETOOTH_DEVICE, null);
    if (deviceAddress == null) {
        Log.d(LOG_TAG, "setBluetoothDeviceName(): deviceAddress is null.");
    }/*from w  ww. j a v a 2  s.  c om*/
    TextView txtDeviceName = (TextView) v.findViewById(R.id.main_bluetooth_device_name);
    if (bluetoothAdapter != null) {
        if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)) {
            txtDeviceName.setText(bluetoothAdapter.getRemoteDevice(deviceAddress).getName());
        }
    }
}

From source file:com.variable.demo.api.MainActivity.java

/**
 * Invokes a new intent to request to start the bluetooth, if not already on.
 *///  w  ww.  j  a  v a2  s.co  m
private boolean ensureBluetoothIsOn() {
    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        Intent btIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        btIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityForResult(btIntent, 200);
        return false;
    }

    return true;
}

From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java

@Override
public void onCreate() {

    super.onCreate();

    // EventManager??
    EventManager.INSTANCE.setController(new MemoryCacheController());

    // LocalOAuth??
    LocalOAuth2Main.initialize(getApplicationContext());

    // add supported profiles
    addProfile(new HostConnectProfile(BluetoothAdapter.getDefaultAdapter()));
    addProfile(new HostNotificationProfile());
    addProfile(new HostDeviceOrientationProfile());
    addProfile(new HostBatteryProfile());
    addProfile(new HostMediaStreamingRecordingProfile());
    addProfile(new HostPhoneProfile());
    addProfile(new HostSettingsProfile());
    addProfile(new HostMediaPlayerProfile());
    // ???/*from  w ww  . ja v  a2  s . c o m*/
    mFileMgr = new FileManager(this);
    addProfile(new HostFileProfile(mFileMgr));
    addProfile(new HostFileDescriptorProfile());
    addProfile(new HostVibrationProfile());
    addProfile(new HostProximityProfile());

    // ???????
    mHostBatteryManager = new HostBatteryManager();
    mHostBatteryManager.getBatteryInfo(this.getContext());

}

From source file:com.mattprecious.notisync.activity.MainActivity.java

@SuppressWarnings("unused")
private void checkBluetooth() {
    if (BluetoothAdapter.getDefaultAdapter() == null && !BuildConfig.DEBUG) {
        Toast.makeText(this, R.string.no_bluetooth, Toast.LENGTH_LONG).show();
        finish();//from  ww w .j  a v  a2  s  .  c  om
    }
}

From source file:org.metawatch.manager.MetaWatchService.java

@Override
public void onCreate() {
    super.onCreate();
    if (Preferences.logging)
        Log.d(MetaWatchStatus.TAG, "MetaWatchService.onCreate()");

    if (!Preferences.loaded)
        loadPreferences(this);

    PreferenceManager.getDefaultSharedPreferences(MetaWatchService.this)
            .registerOnSharedPreferenceChangeListener(prefChangeListener);

    createNotification();/* ww  w  .j  a  va2 s  .com*/

    connectionState = ConnectionState.CONNECTING;

    watchMode.clear();
    watchMode.push(WatchModes.IDLE);

    watchType = WatchType.UNKNOWN;
    watchGen = WatchGen.UNKNOWN;
    Monitors.getInstance().getRTCTimestamp = 0;

    if (bluetoothAdapter == null)
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    Notification.getInstance().startNotificationSender(this);
    Monitors.getInstance().start(this/* , telephonyManager */);

    watchReceiverThread = new WatchReceiverThread("MetaWatch Service Thread");
    watchReceiverThread.setPriority(7);
    watchReceiverThread.start();

    watchSenderThread.execute(protocolSender);
    weatherBatteryPollHandler.post(pollWeatherBattery);

    mIsRunning = true;
}

From source file:com.pdmanager.views.patient.TechnicianActivity.java

private boolean isBluetoothEnabled() {

    try {/* w  ww . j a v  a 2 s.  com*/
        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        if (mBluetoothAdapter != null) {
            return mBluetoothAdapter.isEnabled();

        }

        return false;

    } catch (Exception ex) {

        return false;
    }

}

From source file:com.google.android.car.kitchensink.bluetooth.BluetoothHeadsetFragment.java

@Override
public void onResume() {
    super.onResume();
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    mBluetoothAdapter.getProfileProxy(getContext(), new ProfileServiceListener(),
            BluetoothProfile.HEADSET_CLIENT);
}

From source file:nrec.basil.wimuconsole.SensorSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sensor_settings);

    // Set up the action bar to show a dropdown list which will
    // contain the various sensors that can be configured.  Some
    // sensors are local (camera) some are remote bluetooth devices
    // (IMU, Barometer etc.)
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    // Set up the dropdown list navigation in the action bar.
    actionBar.setListNavigationCallbacks(
            // Specify a SpinnerAdapter to populate the dropdown list.
            new ArrayAdapter<String>(actionBar.getThemedContext(), android.R.layout.simple_list_item_1,
                    android.R.id.text1, getResources().getStringArray(R.array.sensors_list)),
            this);

    // Specify a SpinnerAdapter to populate the wIMU list
    ArrayAdapter<CharSequence> imuAdapter = ArrayAdapter.createFromResource(this, R.array.wimu_list,
            android.R.layout.simple_spinner_item);
    imuAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    imuSpinner = (Spinner) findViewById(R.id.wimulist);
    imuSpinner.setAdapter(imuAdapter);/*  w  w  w  . ja  v  a 2 s  .com*/

    // Load the BASIL start/stop/reset commands
    InputStream input = getResources().openRawResource(R.raw.basilstart);
    try {
        input.read(basilStart, 0, 26);
    } catch (IOException e) {
        Log.e(TAG, "Could not read BASIL start command", e);
    }
    input = getResources().openRawResource(R.raw.basilstop);
    try {
        input.read(basilStop, 0, 26);
    } catch (IOException e) {
        Log.e(TAG, "Could not read BASIL stop command", e);
    }
    input = getResources().openRawResource(R.raw.basilreset);
    try {
        input.read(basilReset, 0, 26);
    } catch (IOException e) {
        Log.e(TAG, "Could not read BASIL reset command", e);
    }

    // Get the default filename for logging
    EditText logfilename = (EditText) findViewById(R.id.logfilename);
    mLogFileName = logfilename.toString();

    // 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();
        return;
    }
}

From source file:org.mobisocial.corral.CorralDownloadClient.java

private Uri getFileOverBluetooth(DbIdentity user, SignedObj obj, CorralDownloadFuture future,
        DownloadProgressCallback callback) throws IOException {
    callback.onProgress(DownloadState.PREPARING_CONNECTION, DownloadChannel.BLUETOOTH, 0);
    String macStr = DbContactAttributes.getAttribute(mContext, user.getLocalId(),
            DbContactAttributes.ATTR_BT_MAC);
    if (macStr == null) {
        throw new IOException("No bluetooth mac address for user");
    }/*ww  w.  ja v a2  s . com*/
    String uuidStr = DbContactAttributes.getAttribute(mContext, user.getLocalId(),
            DbContactAttributes.ATTR_BT_CORRAL_UUID);
    if (uuidStr == null) {
        throw new IOException("No corral uuid for user");
    }
    UUID uuid = UUID.fromString(uuidStr);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice device = adapter.getRemoteDevice(macStr);
    BluetoothSocket socket;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
        socket = device.createInsecureRfcommSocketToServiceRecord(uuid);
    } else {
        socket = device.createRfcommSocketToServiceRecord(uuid);
    }

    // TODO:
    // Custom wire protocol, look for header bits to map to protocol handler.
    Log.d(TAG, "BJD BLUETOOTH CORRAL NOT READY: can't pull file over bluetooth.");
    return null;
}