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:de.bogutzky.psychophysiocollector.app.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case REQUEST_ENABLE_BT:
        if (resultCode == RESULT_OK) {
            Toast.makeText(MainActivity.this, getString(R.string.bluetooth_activated), Toast.LENGTH_LONG)
                    .show();//  w  w w  .  j av a2  s  .  com
        }
        break;

    case PERMISSIONS_REQUEST:
        if (resultCode == RESULT_OK) {
            Toast.makeText(MainActivity.this, getString(R.string.permission_granted), Toast.LENGTH_LONG).show();
        }
        break;

    case MSG_BLUETOOTH_ADDRESS:
        if (resultCode == Activity.RESULT_OK) {
            String bluetoothAddress = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
            Log.d(TAG, "Bluetooth address: " + bluetoothAddress);

            // Check, if device is list view
            if (!getBluetoothAddresses().contains(bluetoothAddress)) {
                Log.d(TAG, "Bluetooth address of a new device");
                addBluetoothAddress(bluetoothAddress);

                bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
                BluetoothDevice device = bluetoothAdapter.getRemoteDevice(bluetoothAddress);

                String deviceName = device.getName();
                if (deviceName == null) {
                    Log.d(TAG, "Device has no device name");
                    deviceName = bluetoothAddress + "";
                }

                // Change list view
                deviceNames.add(deviceName);
                arrayAdapter.notifyDataSetChanged();

                // Check, if device is paired
                Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
                boolean paired = false;
                for (BluetoothDevice pairedDevice : pairedDevices) {
                    if (pairedDevice.getAddress().equals(bluetoothAddress)) {
                        paired = true;
                        Log.d(TAG, "Device already paired");
                    }
                }
                if (!paired) {
                    pairBluetoothDevice(device);
                }

                if (device.getName().startsWith("RN42") & shimmerImuService == null) {
                    Intent intent = new Intent(this, ShimmerImuService.class);
                    startService(intent);
                    getApplicationContext().bindService(intent, shimmerImuServiceConnection,
                            Context.BIND_AUTO_CREATE);
                    registerReceiver(shimmerImuReceiver, new IntentFilter("de.bogutzky.data_collector.app"));
                }

                if (device.getName().startsWith("BH") & bioHarnessService == null) {
                    Intent intent = new Intent(this, BioHarnessService.class);
                    startService(intent);
                    getApplicationContext().bindService(intent, bioHarnessServiceConnection,
                            Context.BIND_AUTO_CREATE);
                    registerReceiver(bioHarnessReceiver, new IntentFilter("de.bogutzky.data_collector.app"));
                }

            } else {
                Toast.makeText(this, getString(R.string.device_is_already_in_list), Toast.LENGTH_LONG).show();
            }
        }
        break;
    case REQUEST_MAIN_COMMAND_SHIMMER:
        if (resultCode == Activity.RESULT_OK) {
            int action = data.getIntExtra("action", 0);
            String bluetoothDeviceAddress = data.getStringExtra("bluetoothDeviceAddress");
            int which = data.getIntExtra("which", 0);
            if (action == 13) {
                showGraph(bluetoothDeviceAddress, REQUEST_MAIN_COMMAND_SHIMMER, which);
            }
        }
        break;
    case REQUEST_MAIN_COMMAND_BIOHARNESS:
        if (resultCode == Activity.RESULT_OK) {
            int action = data.getIntExtra("action", 0);
            String bluetoothDeviceAddress = data.getStringExtra("bluetoothDeviceAddress");
            if (action == 13) {
                showGraph(bluetoothDeviceAddress, REQUEST_MAIN_COMMAND_BIOHARNESS, -1);
            }
        }
        break;
    }
}

From source file:ua.mkh.settings.full.MainActivity.java

@SuppressLint("NewApi")
@Override/*from w w  w .  j  av a2  s  . c  o m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //try {
    String roman = "fonts/Regular.otf";
    String medium = "fonts/Medium.otf";
    String bold = "fonts/Bold.otf";
    String thin = "fonts/Thin.otf";
    typefaceRoman = Typeface.createFromAsset(getAssets(), roman);
    typefaceMedium = Typeface.createFromAsset(getAssets(), medium);
    typefaceBold = Typeface.createFromAsset(getAssets(), bold);
    typefaceThin = Typeface.createFromAsset(getAssets(), thin);

    mSettings = getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);

    ll1 = (LinearLayout) findViewById(R.id.ll1);
    ll1.requestFocus();
    searchView = (SearchView) findViewById(R.id.search);
    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(this);
    searchView.setOnCloseListener(this);

    mListView = (ListView) findViewById(R.id.list);

    b1 = (Button) findViewById(R.id.button1);
    b2 = (Button) findViewById(R.id.button2);
    b11 = (Button) findViewById(R.id.button11);
    b21 = (Button) findViewById(R.id.button21);
    ed1 = (EditText) findViewById(R.id.EditText01);
    ed11 = (EditText) findViewById(R.id.EditText011);

    b21.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            b11.setVisibility(View.GONE);
            b21.setVisibility(View.GONE);
            ed11.clearFocus();
            ed1.clearFocus();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(ed1.getWindowToken(), 0);
            ed11.setText("");
            ed1.setText("");
            LinearLayout list_res_top = (LinearLayout) findViewById(R.id.list_res_top);
            list_res_top.setVisibility(View.GONE);
            LinearLayout list_res = (LinearLayout) findViewById(R.id.list_res);
            list_res.setVisibility(View.GONE);
            ll1.setVisibility(View.VISIBLE);
            sear = false;
        }
    });

    ed1.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                b11.setVisibility(View.VISIBLE);
                b21.setVisibility(View.VISIBLE);
                LinearLayout list_res_top = (LinearLayout) findViewById(R.id.list_res_top);
                list_res_top.setVisibility(View.VISIBLE);
                LinearLayout list_res = (LinearLayout) findViewById(R.id.list_res);
                list_res.setVisibility(View.VISIBLE);
                sear = true;

                //ll1.setVisibility(View.INVISIBLE);

                ed11.requestFocus();
                ed1.clearFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(ed11, InputMethodManager.SHOW_IMPLICIT);
                //LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                //lp.setMargins(0, 0, 0, 0);
                //ll1.setLayoutParams(lp);

            } else {
                ll1.setVisibility(View.GONE);
                b11.setVisibility(View.VISIBLE);
                LinearLayout list_res = (LinearLayout) findViewById(R.id.list_res);
                list_res.setVisibility(View.VISIBLE);
                //LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                //lp.setMargins(0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 39, getResources().getDisplayMetrics()), 0, 0);
                //ll1.setLayoutParams(lp);
            }
        }
    });

    ed11.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            searchView.setQuery(cs, false);
            mListView.setVisibility(View.VISIBLE);

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

        @Override
        public void afterTextChanged(Editable arg0) {

        }
    });

    mDbHelper = new CustomersDbAdapter(this);
    mDbHelper.open();

    /*
            
    //Clean all Customers
    mDbHelper.deleteAllCustomers();
            
    */
    //////////////////////

    LinearLayoutWiFi = (LinearLayout) findViewById(R.id.LinearLayoutWiFi);
    LinearLayoutBluetooth = (LinearLayout) findViewById(R.id.LinearLayoutBluetooth);
    LinearLayoutSotSvyaz = (LinearLayout) findViewById(R.id.LinearLayoutSotSvyaz);
    LinearLayoutOperator = (LinearLayout) findViewById(R.id.LinearLayoutOperator);
    LinearLayoutGeo = (LinearLayout) findViewById(R.id.LinearLayoutGeo);
    LinearLayoutNotif = (LinearLayout) findViewById(R.id.LinearLayoutNotif);
    LinearLayoutControl = (LinearLayout) findViewById(R.id.LinearLayoutControl);
    LinearLayoutMail = (LinearLayout) findViewById(R.id.LinearLayoutMail);
    LinearLayoutNotes = (LinearLayout) findViewById(R.id.LinearLayoutNotes);
    LinearLayoutMessages = (LinearLayout) findViewById(R.id.LinearLayoutMessages);
    LinearLayoutPhone = (LinearLayout) findViewById(R.id.LinearLayoutPhone);
    LinearLayoutSafari = (LinearLayout) findViewById(R.id.LinearLayoutSafari);
    LinearLayoutMusic = (LinearLayout) findViewById(R.id.LinearLayoutMusic);
    LinearLayoutCompass = (LinearLayout) findViewById(R.id.LinearLayoutCompass);
    LinearLayoutWeather = (LinearLayout) findViewById(R.id.LinearLayoutWeather);
    LinearLayoutGameCenter = (LinearLayout) findViewById(R.id.LinearLayoutGameCenter);
    LinearLayoutPasscode = (LinearLayout) findViewById(R.id.LinearLayoutPasscode);
    LinearLayoutPrivacy = (LinearLayout) findViewById(R.id.LinearLayoutPrivacy);
    LinearLayoutApn = (LinearLayout) findViewById(R.id.LinearLayoutApn);
    LinearLayoutCloud = (LinearLayout) findViewById(R.id.LinearLayoutCloud);
    LinearLayoutTunes = (LinearLayout) findViewById(R.id.LinearLayoutTunes);
    LinearLayoutMaps = (LinearLayout) findViewById(R.id.LinearLayoutMaps);
    LinearLayoutVk = (LinearLayout) findViewById(R.id.LinearLayoutVk);
    LinearLayoutViber = (LinearLayout) findViewById(R.id.LinearLayoutViber);
    LinearLayoutOk = (LinearLayout) findViewById(R.id.LinearLayoutOK);
    LinearLayoutSkype = (LinearLayout) findViewById(R.id.LinearLayoutSkype);
    LinearLayoutWhatsapp = (LinearLayout) findViewById(R.id.LinearLayoutWhatsApp);
    LinearLayoutTwitter = (LinearLayout) findViewById(R.id.LinearLayoutTwitter);
    LinearLayoutFacebook = (LinearLayout) findViewById(R.id.LinearLayoutFacebook);
    LinearLayoutInstagram = (LinearLayout) findViewById(R.id.LinearLayoutInstagram);

    LinearLayoutNew1 = (LinearLayout) findViewById(R.id.LinearLayoutApp1);
    LinearLayoutNew2 = (LinearLayout) findViewById(R.id.LinearLayoutApp2);
    LinearLayoutNew3 = (LinearLayout) findViewById(R.id.LinearLayoutApp3);
    LinearLayoutNew4 = (LinearLayout) findViewById(R.id.LinearLayoutApp4);

    LinearLayoutNew1.setVisibility(View.GONE);
    LinearLayoutNew2.setVisibility(View.GONE);
    LinearLayoutNew3.setVisibility(View.GONE);
    LinearLayoutNew4.setVisibility(View.GONE);

    LinearLayoutGeo.setVisibility(View.GONE);
    LinearLayoutMail.setVisibility(View.GONE);
    LinearLayoutNotes.setVisibility(View.GONE);
    LinearLayoutMessages.setVisibility(View.GONE);
    LinearLayoutPhone.setVisibility(View.GONE);
    LinearLayoutSafari.setVisibility(View.GONE);
    LinearLayoutMusic.setVisibility(View.GONE);
    LinearLayoutCompass.setVisibility(View.GONE);
    LinearLayoutWeather.setVisibility(View.GONE);
    LinearLayoutGameCenter.setVisibility(View.GONE);
    LinearLayoutNotif.setVisibility(View.GONE);
    LinearLayoutControl.setVisibility(View.GONE);
    LinearLayoutTunes.setVisibility(View.GONE);
    LinearLayoutMaps.setVisibility(View.GONE);
    LinearLayoutVk.setVisibility(View.GONE);
    LinearLayoutViber.setVisibility(View.GONE);
    LinearLayoutOk.setVisibility(View.GONE);
    LinearLayoutSkype.setVisibility(View.GONE);
    LinearLayoutWhatsapp.setVisibility(View.GONE);
    LinearLayoutTwitter.setVisibility(View.GONE);
    LinearLayoutFacebook.setVisibility(View.GONE);
    LinearLayoutInstagram.setVisibility(View.GONE);

    textwifi = (TextView) findViewById(R.id.textwifi);
    textbt = (TextView) findViewById(R.id.textbt);
    TextOper = (TextView) findViewById(R.id.TextOper);
    textVPN = (TextView) findViewById(R.id.TextView01);

    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    btn_avia = (Button) findViewById(R.id.Button01);
    tb_am = (ToggleButton) findViewById(R.id.ToggleButton01);
    tb_am.setOnClickListener(this);

    btn_wifi = (Button) findViewById(R.id.ButtonWifi);
    btn_wifi.setOnClickListener(this);

    btn_bluetooth = (Button) findViewById(R.id.ButtonBluetooth);
    btn_bluetooth.setOnClickListener(this);

    btn_sota = (Button) findViewById(R.id.ButtonSota);
    btn_sota.setOnClickListener(this);

    startService(new Intent(this, NotificationService.class));

    btn_operator = (Button) findViewById(R.id.ButtonOperator);
    btn_operator.setOnClickListener(this);

    btn_osnova = (Button) findViewById(R.id.ButtonOsnova);
    btn_osnova.setOnClickListener(this);

    btn_zvuki = (Button) findViewById(R.id.ButtonZvuki);
    btn_zvuki.setOnClickListener(this);

    btn_oboi = (Button) findViewById(R.id.ButtonOboi);
    btn_oboi.setOnClickListener(this);

    btn_gps = (Button) findViewById(R.id.ButtonGeo);
    btn_gps.setOnClickListener(this);

    btn_passcode = (Button) findViewById(R.id.ButtonPasscode);
    btn_passcode.setOnClickListener(this);

    btn_battery = (Button) findViewById(R.id.ButtonBattery);
    btn_battery.setOnClickListener(this);

    btn_privacy = (Button) findViewById(R.id.ButtonPrivacy);
    btn_privacy.setOnClickListener(this);

    btn_notification = (Button) findViewById(R.id.ButtonNotification);
    btn_notification.setOnClickListener(this);

    btn_control = (Button) findViewById(R.id.ButtonControl);
    btn_control.setOnClickListener(this);

    btn_disturb = (Button) findViewById(R.id.ButtonDisturb);
    btn_disturb.setOnClickListener(this);

    btn_mail = (Button) findViewById(R.id.ButtonMail);
    btn_mail.setOnClickListener(this);

    btn_notes = (Button) findViewById(R.id.ButtonNotes);
    btn_notes.setOnClickListener(this);

    btn_messages = (Button) findViewById(R.id.ButtonMessages);
    btn_messages.setOnClickListener(this);

    btn_phone = (Button) findViewById(R.id.ButtonPhone);
    btn_phone.setOnClickListener(this);

    btn_safari = (Button) findViewById(R.id.ButtonSafari);
    btn_safari.setOnClickListener(this);

    btn_music = (Button) findViewById(R.id.ButtonMusic);
    btn_music.setOnClickListener(this);

    btn_compass = (Button) findViewById(R.id.ButtonCompass);
    btn_compass.setOnClickListener(this);

    btn_weather = (Button) findViewById(R.id.ButtonWeather);
    btn_weather.setOnClickListener(this);

    btn_games = (Button) findViewById(R.id.ButtonGameCenter);
    btn_games.setOnClickListener(this);

    btn_maps = (Button) findViewById(R.id.ButtonMaps);
    btn_maps.setOnClickListener(this);

    btn_vk = (Button) findViewById(R.id.ButtonVk);
    btn_vk.setOnClickListener(this);

    btn_viber = (Button) findViewById(R.id.ButtonViber);
    btn_viber.setOnClickListener(this);

    btn_ok = (Button) findViewById(R.id.ButtonOk);
    btn_ok.setOnClickListener(this);

    btn_skype = (Button) findViewById(R.id.ButtonSkype);
    btn_skype.setOnClickListener(this);

    btn_whatsapp = (Button) findViewById(R.id.ButtonWhatsapp);
    btn_whatsapp.setOnClickListener(this);

    btn_twitter = (Button) findViewById(R.id.ButtonTwitter);
    btn_twitter.setOnClickListener(this);

    btn_facebook = (Button) findViewById(R.id.ButtonFacebook);
    btn_facebook.setOnClickListener(this);

    btn_instagram = (Button) findViewById(R.id.ButtonInstagram);
    btn_instagram.setOnClickListener(this);

    btn_new1 = (Button) findViewById(R.id.Button02);
    btn_new1.setOnClickListener(this);

    btn_new2 = (Button) findViewById(R.id.Button03);
    btn_new2.setOnClickListener(this);

    btn_new3 = (Button) findViewById(R.id.Button04);
    btn_new3.setOnClickListener(this);

    btn_new4 = (Button) findViewById(R.id.Button05);
    btn_new4.setOnClickListener(this);

    btn_vpn = (Button) findViewById(R.id.Button06);
    btn_vpn.setOnClickListener(this);

    btn_display = (Button) findViewById(R.id.ButtonDisplay);
    btn_display.setOnClickListener(this);

    btn_iCloud = (Button) findViewById(R.id.ButtonCloud);
    btn_iCloud.setOnClickListener(this);

    btn_iTunes = (Button) findViewById(R.id.ButtonTunes);
    btn_iTunes.setOnClickListener(this);

    buttonBack = (Button) findViewById(R.id.buttonBack);
    btn_menu_settings = (Button) findViewById(R.id.ButtonMenuSettings);
    btn_menu_cancel = (Button) findViewById(R.id.ButtonMenuCancel);

    textView1 = (TextView) findViewById(R.id.textView1);
    textView2 = (TextView) findViewById(R.id.textView2);
    textView3 = (TextView) findViewById(R.id.textView3);

    text_app_main = (TextView) findViewById(R.id.text_app_main);

    text_app_main.setText(R.string.text_app_name);

    ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);
    imageView2.setVisibility(View.GONE);

    text_app_main.setTypeface(typefaceBold);
    btn_avia.setTypeface(typefaceRoman);
    //textView1.setTypeface(typefaceRoman);
    textView3.setTypeface(typefaceRoman);
    btn_wifi.setTypeface(typefaceRoman);
    btn_bluetooth.setTypeface(typefaceRoman);
    btn_sota.setTypeface(typefaceRoman);
    btn_operator.setTypeface(typefaceRoman);
    btn_osnova.setTypeface(typefaceRoman);
    btn_passcode.setTypeface(typefaceRoman);
    btn_battery.setTypeface(typefaceRoman);
    btn_privacy.setTypeface(typefaceRoman);
    btn_zvuki.setTypeface(typefaceRoman);
    btn_oboi.setTypeface(typefaceRoman);
    btn_notification.setTypeface(typefaceRoman);
    btn_control.setTypeface(typefaceRoman);
    btn_disturb.setTypeface(typefaceRoman);
    btn_gps.setTypeface(typefaceRoman);
    btn_mail.setTypeface(typefaceRoman);
    btn_notes.setTypeface(typefaceRoman);
    btn_messages.setTypeface(typefaceRoman);
    btn_phone.setTypeface(typefaceRoman);
    btn_safari.setTypeface(typefaceRoman);
    btn_music.setTypeface(typefaceRoman);
    btn_compass.setTypeface(typefaceRoman);
    btn_weather.setTypeface(typefaceRoman);
    btn_games.setTypeface(typefaceRoman);
    btn_new1.setTypeface(typefaceRoman);
    btn_new2.setTypeface(typefaceRoman);
    btn_new3.setTypeface(typefaceRoman);
    btn_new4.setTypeface(typefaceRoman);
    btn_vpn.setTypeface(typefaceRoman);
    btn_display.setTypeface(typefaceRoman);
    btn_maps.setTypeface(typefaceRoman);
    btn_vk.setTypeface(typefaceRoman);
    btn_viber.setTypeface(typefaceRoman);
    btn_ok.setTypeface(typefaceRoman);
    btn_skype.setTypeface(typefaceRoman);
    btn_whatsapp.setTypeface(typefaceRoman);
    btn_twitter.setTypeface(typefaceRoman);
    btn_facebook.setTypeface(typefaceRoman);
    btn_instagram.setTypeface(typefaceRoman);

    btn_iCloud.setTypeface(typefaceRoman);
    btn_iTunes.setTypeface(typefaceRoman);

    textwifi.setTypeface(typefaceRoman);
    textbt.setTypeface(typefaceRoman);
    TextOper.setTypeface(typefaceRoman);
    textVPN.setTypeface(typefaceRoman);

    //LinearLayoutPrivacy.setVisibility(View.GONE);
    //LinearLayoutApn.setVisibility(View.GONE);
    //LinearLayoutPasscode.setVisibility(View.GONE);
    //layoutTunes.setVisibility(View.GONE);

    //////////////////START///////////////////   

    ///////////////////APP//////////////
    pm = this.getPackageManager();
    //Notification 
    notif_inoty = pm.getLaunchIntentForPackage("net.suckga.inoty");
    notif_espier = pm.getLaunchIntentForPackage("mobi.espier.launcher.plugin.notifications7pro");
    //Control Center
    control_hi = pm.getLaunchIntentForPackage("com.hi.apps.studio.control.center");
    control_espier = pm.getLaunchIntentForPackage("mobi.espier.launcher.plugin.controller7pro");
    //Mail
    mail_stok = pm.getLaunchIntentForPackage("com.android.email");
    //Phone
    phone_stok = pm.getLaunchIntentForPackage("com.android.dialer");
    //Messages
    messages_stok = pm.getLaunchIntentForPackage("com.android.mms");
    //Safari
    safari_stok = pm.getLaunchIntentForPackage("com.android.browser");
    //Music;
    music_stok = pm.getLaunchIntentForPackage("com.android.music");
    //VK
    vk_stok = pm.getLaunchIntentForPackage("com.vkontakte.android");
    //Viber
    viber_stok = pm.getLaunchIntentForPackage("com.viber.voip");
    //Ok
    ok_stok = pm.getLaunchIntentForPackage("ru.ok.android");
    //Skype
    skype_stok = pm.getLaunchIntentForPackage("com.skype.raider");
    //WhatsApp!!!!
    whatsapp_stok = pm.getLaunchIntentForPackage("com.whatsapp");
    //Twitter
    twitter_stok = pm.getLaunchIntentForPackage("com.twitter.android");
    //Facebook
    facebook_stok = pm.getLaunchIntentForPackage("com.facebook.katana");
    //Instagram
    instagram_stok = pm.getLaunchIntentForPackage("com.instagram.android");
    //Maps
    maps_stok = pm.getLaunchIntentForPackage("com.google.android.apps.maps");

    bt = BluetoothAdapter.getDefaultAdapter();
    //Check Availability of bluetooth
    if (bt == null) {
        LinearLayoutBluetooth.setVisibility(View.GONE);
    }
}

From source file:com.example.shoe.DirectionsTest.java

public void bluetooth() {
    // create a bluetooth adapter
    BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
    if (bluetooth != null) {
        // continue with setup, an adapter exists
        String status;//from  w  w w .j  a va 2s  .com
        if (bluetooth.isEnabled()) {
            // get address of bluetooth device
            String mydeviceaddress = bluetooth.getAddress();
            // get name of bluetooth device
            String mydevicename = bluetooth.getName();
            int stateInt = bluetooth.getState();
            String state = "";

            switch (stateInt) {
            case 0:
                state = "STATE_DISCONNECTING";
                break;
            case 1:
                state = "STATE_CONNECTING";
                break;
            case 2:
                state = "STATE_CONNECTED";
                break;
            case 10:
                state = "STATE_OFF";
                break;
            case 11:
                state = "STATE_TURNING_ON";
                break;
            case 12:
                state = "STATE_ON";
                break;
            case 13:
                state = "STATE_TURNING_OFF";
                break;
            case 20:
                state = "SCAN_MODE_NONE";
                break;
            case 21:
                state = "SCAN_MODE_CONNECTABLE";
                break;
            case 23:
                state = "SCAN_MODE_CONNECTABLE_DISCOVERABLE";
                break;
            default:
                state = "UNKNOWN_STATE";
                break;
            }

            status = mydevicename + " : " + mydeviceaddress + " : " + state;
            //status = mydevicename + " : " + mydeviceaddress;
        } else {
            status = "Bluetooth is not Enabled.";
        }
        Toast.makeText(this, status, Toast.LENGTH_LONG).show();

    }

}

From source file:com.juce.jucedemo.JuceDemo.java

public BluetoothManager getAndroidBluetoothManager() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

    if (adapter == null)
        return null;

    if (adapter.getBluetoothLeScanner() == null)
        return null;

    synchronized (JuceDemo.class) {
        if (bluetoothManager == null)
            bluetoothManager = new BluetoothManager();
    }//from w w  w. ja  v a  2  s. c  o m

    return bluetoothManager;
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void connectAllShimmerImus() {
    if (bluetoothAdapter == null)
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
    int count = 0;
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if (device.getName().contains("RN42")) {
                if (bluetoothAddresses.contains(device.getAddress())) {
                    if (shimmerImuService != null) {
                        shimmerImuService.connectShimmerImu(device.getAddress(), Integer.toString(count),
                                new ShimmerImuHandler(this, "imu-" + device.getName().toLowerCase() + ".csv",
                                        2500));
                        count++;/*from  w  w  w .  j a v a2 s .  co  m*/
                    }
                }
            }
        }
    }
}

From source file:org.thecongers.mtpms.MainActivity.java

private boolean btConnect() {
    btAdapter = BluetoothAdapter.getDefaultAdapter();
    checkBTState();/* w  w  w  . j av a2s .  c  om*/
    if (btAdapter != null) {
        Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
        // If there are paired devices
        if (pairedDevices.size() > 0) {
            // Loop through paired devices
            for (BluetoothDevice device : pairedDevices) {
                if (device.getName().contains("iTPMS")) {
                    address = device.getAddress();
                    Log.d(TAG, "Paired iTPMSystem found: " + device.getName() + " " + device.getAddress());
                }
            }
            if (address == null) {
                Toast.makeText(MainActivity.this, getResources().getString(R.string.toast_noPaired),
                        Toast.LENGTH_LONG).show();
                return false;
            }
        }
        if (address != null) {
            // Set up a pointer to the remote node using it's address.
            BluetoothDevice device = btAdapter.getRemoteDevice(address);
            btConnectThread = new ConnectThread(device);
            btConnectThread.start();
        } else {
            Toast.makeText(MainActivity.this, getResources().getString(R.string.toast_noPaired),
                    Toast.LENGTH_LONG).show();
            return false;
        }
        return true;
    }
    Log.d(TAG, "Bluetooth not supported");
    return false;
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void connectBioHarness() {
    if (bluetoothAdapter == null)
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if (device.getName().startsWith("BH")) {
                if (bluetoothAddresses.contains(device.getAddress())) {
                    if (bioHarnessService != null) {
                        bioHarnessService.connectBioHarness(device.getAddress(),
                                new BioHarnessHandler(this, new int[] { 100, 1000 }));
                    }/*from   ww  w .  j  a v a2  s .co m*/
                }
            }
        }
    }
}

From source file:com.piusvelte.taplock.client.core.TapLockSettings.java

private void addDevice() {
    // Get a set of currently paired devices
    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter.isEnabled()) {
        Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
        // launch dialog to select device
        if (pairedDevices.size() > 0) {
            int p = 0;
            final String[] pairedDeviceNames = new String[pairedDevices.size()];
            final String[] pairedDeviceAddresses = new String[pairedDevices.size()];
            for (BluetoothDevice device : pairedDevices) {
                pairedDeviceNames[p] = device.getName();
                pairedDeviceAddresses[p++] = device.getAddress();
            }//from w w w. jav  a  2s .c o  m
            mDialog = new AlertDialog.Builder(TapLockSettings.this)
                    .setItems(pairedDeviceNames, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            addNewDevice(pairedDeviceNames[which], pairedDeviceAddresses[which]);
                        }

                    })
                    .setPositiveButton(getString(R.string.btn_bt_scan), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (mServiceInterface != null) {
                                try {
                                    mServiceInterface.requestDiscovery();
                                    mProgressDialog = new ProgressDialog(TapLockSettings.this);
                                    mProgressDialog.setMessage(getString(R.string.msg_scanning));
                                    mProgressDialog.setCancelable(true);
                                    mProgressDialog.show();
                                } catch (RemoteException e) {
                                    Log.e(TAG, e.toString());
                                }
                            }
                        }
                    }).create();
            mDialog.show();
        } else {
            if (mServiceInterface != null) {
                try {
                    mServiceInterface.requestDiscovery();
                    mProgressDialog = new ProgressDialog(this);
                    mProgressDialog.setMessage(getString(R.string.msg_scanning));
                    mProgressDialog.setCancelable(true);
                    mProgressDialog.show();
                } catch (RemoteException e) {
                    Log.e(TAG, e.toString());
                }
            }
        }
    } else {
        mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle(R.string.ttl_enablebt)
                .setMessage(R.string.msg_enablebt)
                .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (mServiceInterface != null) {
                            try {
                                mServiceInterface.enableBluetooth();
                            } catch (RemoteException e) {
                                Log.e(TAG, e.toString());
                            }
                        }
                    }
                }).create();
        mDialog.show();
    }
}

From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initapp = true;/*from   w  w w  .j  ava2 s  . c  o m*/
    //sandbox();
    initialized = false;
    if (android.os.Build.VERSION.SDK_INT > 10) {
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
        //getOverflowMenu();
    }
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null) {
        finishDialogNoBluetooth();
        return;
    }
    setContentView(R.layout.term_activity);
    Message msg = new Message();
    msg.what = STOPSPLASH;
    splashHandler.sendMessageDelayed(msg, SPLASHTIME);
}

From source file:org.bcsphere.bluetooth.tools.Tools.java

public static boolean getBluetoothState() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter.isEnabled()) {
        return true;
    } else {// w w w . j  ava2  s . com
        return false;
    }
}