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.authorwjf.bounce.BluetoothChat.java

@Override
public void onCreate() {
    super.onCreate();

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    setupChat();//from w  w w .  ja v  a  2  s .c o  m

    // If the adapter is null, then Bluetooth is not supported
    /*if (mBluetoothAdapter == null) {
       Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
       return;
    }*/
}

From source file:com.digitalobstaclecourse.bluefinder.FindCar.java

void insert_paired_devices_into_database() {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null) {
        showNoBluetoothDialog();/*w ww.  j  a v a2s .com*/
    }
    Set<BluetoothDevice> paired_devices = null;
    if (mBluetoothAdapter != null) {
        paired_devices = mBluetoothAdapter.getBondedDevices();
    }
    DataAccessModule dataAccess = DataAccessModule.getDataAccessModule(this);
    if (paired_devices != null) {
        for (BluetoothDevice d : paired_devices) {
            //Log.d(TAG, "msg" + d.getName());
            dataAccess.add_device(d);
        }
    } else {
        //Log.e(TAG, "paired_devices  == null");
    }
    dataAccess.add_event("Power Disconnect Location", "POWER");
    //Log.d(TAG, "Logging all devices");
}

From source file:com.example.android.bluetoothchat.BluetoothChatFragment2.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);// ww  w. j a v  a2  s .  c  om
    // 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();
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestPermission();
    }

    mMainHandler = new Handler(Looper.getMainLooper());

}

From source file:org.jfedor.nxtremotecontrol.ChooseDeviceActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.device_list);
    setResult(Activity.RESULT_CANCELED);
    Button scanButton = (Button) findViewById(R.id.button_scan);
    scanButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            doDiscovery();/* ww  w .j  a v a2  s.c  o m*/
            v.setVisibility(View.GONE);

        }
    });

    mPairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);
    mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);

    ListView pairedListView = (ListView) findViewById(R.id.paired_devices);
    pairedListView.setAdapter(mPairedDevicesArrayAdapter);
    pairedListView.setOnItemClickListener(mDeviceClickListener);

    ListView newDevicesListView = (ListView) findViewById(R.id.new_devices);
    newDevicesListView.setAdapter(mNewDevicesArrayAdapter);
    newDevicesListView.setOnItemClickListener(mDeviceClickListener);

    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    this.registerReceiver(mReceiver, filter);

    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    this.registerReceiver(mReceiver, filter);

    mBtAdapter = BluetoothAdapter.getDefaultAdapter();

    Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();

    boolean empty = true;

    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if ((device.getBluetoothClass() != null)
                    && (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.TOY_ROBOT)) {
                mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
                empty = false;
            }
        }
    }
    if (!empty) {
        findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
        findViewById(R.id.no_devices).setVisibility(View.GONE);
    }

    if (checkPlayService()) {
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
}

From source file:com.pendragon.blueconnect.BluetoothChat.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (D)/*from  w w  w. j  av  a2 s .  c  o  m*/
        Log.e(TAG, "+++ ON CREATE +++");

    //Para las notificaciones
    notificationID = 1;

    // Le ponemos un layout
    setContentView(R.layout.main);

    // obtenemos el adaptador propio
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // Si el adaptador es null, no tenemos BT en el movil
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    if (MySingleton.getInstance().getInitBluetooth() == 0) {

        Intent serverIntent = null;
        serverIntent = new Intent(this, MainActivity.class);
        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
        MySingleton.getInstance().setInitBluetooth(1);
    }
    instance = this;
}

From source file:com.google.android.apps.forscience.whistlepunk.devicemanager.ManageDevicesActivity.java

private void setFragment() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    Fragment fragment;//w  w  w.ja v  a  2 s  .c o  m
    if (adapter.isEnabled() && ScanDisabledFragment.hasScanPermission(this)) {
        mManageFragment = new ManageDevicesFragment();
        fragment = mManageFragment;
    } else {
        fragment = new ScanDisabledFragment();
        mManageFragment = null;
    }
    Bundle args = new Bundle();
    args.putString(EXTRA_EXPERIMENT_ID, getIntent().getStringExtra(EXTRA_EXPERIMENT_ID));
    fragment.setArguments(args);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.fragment, fragment);
    ft.commitAllowingStateLoss();
}

From source file:org.deviceconnect.android.deviceplugin.sphero.setting.fragment.DeviceSelectionPageFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    isThreadRunning = true;/*w w  w. j av  a  2s .  co  m*/
    new Thread(new Runnable() {
        @Override
        public void run() {
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (mBluetoothAdapter == null) {
                return;
            }
            int prevState = mBluetoothAdapter.getState();
            while (isThreadRunning) {
                if (prevState != mBluetoothAdapter.getState()) {
                    if ((mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON)
                            && (prevState == BluetoothAdapter.STATE_TURNING_ON
                                    || prevState == BluetoothAdapter.STATE_OFF)) {
                        threadHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                stopDiscovery();
                                startDiscovery();
                            }
                        });
                    }
                    prevState = mBluetoothAdapter.getState();
                }

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
}

From source file:xqs.JoystickFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);//from  w ww . j a va2s.c  om
    // 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();
    }
    mJoystickDriver = JoystickDriver.getInstance(mJoystickCallBack.getUsbManager(),
            mJoystickCallBack.getUsbDevice(), mDriver);
}

From source file:com.example.android.bluetoothchat.BluetoothFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);/* ww  w  . ja  v a 2  s  .  co  m*/
    // 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();
    }

    TelephonyManager telManager = (TelephonyManager) getActivity()
            .getSystemService(getActivity().TELEPHONY_SERVICE);
    phoneNum = telManager.getLine1Number();
}

From source file:com.techjoynt.android.nxt.fragment.NXTFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(getActivity().getApplicationContext());
    readPreferences(prefs, null);/*w  w  w .  jav a2s  .co  m*/
    prefs.registerOnSharedPreferenceChangeListener(this);

    if (savedInstanceState != null) {
        mNewLaunch = false;
        mDeviceAddress = savedInstanceState.getString("device_address");
        if (mDeviceAddress != null) {
            mSavedState = NXTTalker.STATE_CONNECTED;
        }

        if (savedInstanceState.containsKey("power")) {
            mPower = savedInstanceState.getInt("power");
        }
        if (savedInstanceState.containsKey("controls_mode")) {
            mControlsMode = savedInstanceState.getInt("controls_mode");
        }
    }

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    if (mBluetoothAdapter == null) {
        Toast.makeText(getActivity(), "Bluetooth is not available", Toast.LENGTH_LONG).show();
        getActivity().finish();
        return;
    }

    setupUI();
    mNXTTalker = new NXTTalker(mHandler);
}