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.shenqu.jlplayer.nRFUARTv2.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rfuart_main);

    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();/*from  www  .  j  a  v a  2  s.c  o  m*/
        return;
    }

    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);

    edtMessage = (EditText) findViewById(R.id.sendText);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnConnectDisconnect.setOnClickListener(this);
    btnSend = (Button) findViewById(R.id.sendButton);
    btnSend.setOnClickListener(this);

    /**
     * ? nRFUART service
     * */
    Intent bindIntent = new Intent(this, UartService.class);
    bindService(bindIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
    LocalBroadcastManager.getInstance(this).registerReceiver(UARTStatusChangeReceiver,
            makeGattUpdateIntentFilter());
}

From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    mCordova = cordova;/*from www.j a  v  a2  s  .c o  m*/
    try {
        mBtadapter = BluetoothAdapter.getDefaultAdapter();
    } catch (RuntimeException e) {
        XLog.e(CLASS_NAME, "init: RuntimeException");
        return;
    }
    mFoundDevices = new ArrayList<BluetoothDevice>();
    Context context = cordova.getActivity();

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

    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    context.registerReceiver(mReceiver, filter);

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

    filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    context.registerReceiver(mReceiver, filter);
}

From source file:com.sdingba.su.lanya.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBtAdapter = BluetoothAdapter.getDefaultAdapter();

    if (mBtAdapter == null) {
        //            Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        Toast.makeText(this, " Bluetooth is not available------Bluetooth ??", Toast.LENGTH_LONG)
                .show();//from   ww  w  .  j av a  2s  .  co m
        finish();
        return;
    }
    //        showMessage("??");

    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnSend = (Button) findViewById(R.id.sendButton);
    edtMessage = (EditText) findViewById(R.id.sendText);
    service_init();

    // Handler Disconnect & Connect button
    btnConnectDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (!mBtAdapter.isEnabled()) {
                //                      mBtAdapter.isEnabled()  == null ??
                //
                //                    showMessage("mBtAdapter.isEnabled() = "+mBtAdapter.isEnabled());
                //mBtAdapter.isEnabled()::::Return true if Bluetooth is currently enabled and ready for use.
                //Equivalent to: getBluetoothState() == STATE_ON

                Log.i(TAG, "onClick - BT not enabled yet");
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            } else {
                //TODO   BUG
                //// TODO: 16-6-5  ???   ?

                //   Connect ?? listView
                showMessage(" ??" + mState + "    "
                        + "    21 = UART_PROFILE_DISCONNECTED ; 20 = connection");
                if (btnConnectDisconnect.getText().equals("Connect")) {
                    //Connect button pressed, open DeviceListActivity
                    // class, with popup windows that scan for devices
                    // showMessage(" =-=======-= ");
                    Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class);
                    startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
                } else {

                    showMessage(" ******** ");
                    //Disconnect button pressed
                    if (mDevice != null) {
                        mService.disconnect();
                    }
                }
            }
        }
    });

    //// TODO: 16-6-13 ]   ? ?

    //??
    // Handler Send button
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = (EditText) findViewById(R.id.sendText);
            String message = editText.getText().toString();
            byte[] value;
            try {
                //send data to service
                value = message.getBytes("UTF-8");
                mService.writeRXCharacteristic(value);

                //Update the log with time stamp
                String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                listAdapter.add("[" + currentDateTimeString + "] TX: " + message);

                messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);

                edtMessage.setText("");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Set initial UI state

}

From source file:sean.dataexchange.BluetoothChatFragment.java

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

    test = new SurveyPointHandler("TestFile.txt", this.getContext());
    System.out.println("Fragment Accessed to File");

    setHasOptionsMenu(true);/*  w  w w .j a v  a  2  s.com*/
    // 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();
    }
}

From source file:com.example.android.BluetoothSerial.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   w  ww  .  j  a va2s  .c  o m
public BluetoothSerialService(Context context, Handler handler) {
    mAdapter = BluetoothAdapter.getDefaultAdapter();
    mState = STATE_NONE;
    mHandler = handler;
}

From source file:com.example.android.comunicacaoBluetooth.BluetoothChatFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);// ww  w .  j a  v a2 s . co  m
    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    PersistenciaTextoBinario.getInstance().criarStream();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        FragmentActivity activity = getActivity();
        Toast.makeText(activity, "O Bluetooth no est disponvel", Toast.LENGTH_LONG).show();
        activity.finish();
    }
}

From source file:com.bluetooth.comp529.bluetoothchatproj.chat.BluetoothChatFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);//w  w  w . j  a  va  2s.c  om
    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported on this device
    if (mBluetoothAdapter == null) {
        FragmentActivity activity = getActivity();
        Toast.makeText(activity, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        activity.finish();
    }

    ensureDiscoverable();

}

From source file:com.dipesan.miniatm.miniatm.services.BluetoothConnexionManager.java

@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
    case BluetoothAdapter.ACTION_STATE_CHANGED:
        if (BluetoothAdapter.getDefaultAdapter().isEnabled()) {
            connect();/* w w  w  .  j a  v  a 2s. com*/
        }
        break;
    }
}

From source file:com.ght.cerberus.StatusFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);//from w w w.  j  av  a 2  s.  c o  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();
    }
    mRobot = new ImageView(getContext());
    mStateText = new TextView(getContext());
}

From source file:com.manuelmazzuola.speedtogglebluetooth.service.MonitorSpeed.java

@Override
public void onCreate() {
    DEFAULT_TITLE = this.getString(R.string.app_name);
    DEFAULT_MESSAGE = this.getString(R.string.service_is_running);
    WAITING_MESSAGE = this.getString(R.string.waiting_device);
    WAITING_TO_SLOWDOWN = this.getString(R.string.waiting_to_slowdown);
    activated = BluetoothAdapter.getDefaultAdapter().isEnabled();
    running = Boolean.FALSE;/*w  w w  . ja va  2s.  c  o  m*/
}