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.example.bluetooth_faster_connection.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (D)/*ww w . j a va2 s. com*/
        Log.e(TAG, "+++ ON CREATE +++");

    // Set up the window layout
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

    // Set up the custom title
    mTitle = (TextView) findViewById(R.id.title_left_text);
    mTitle.setText(R.string.app_name);
    mTitle = (TextView) findViewById(R.id.title_right_text);
    mInfo = (TextView) findViewById(R.id.myText);

    Button mButton = (Button) findViewById(R.id.myButton);
    mButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            openOptionsMenu();
        }
    });

    // 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;
    }

    // register for background service broadcast.
    IntentFilter ifilt = new IntentFilter(DeviceDicoverService.DEVICE_CONNECTION_ADDRESS);
    ifilt.addAction(DeviceDicoverService.DEVICE_CONNECTION_INFO);
    registerReceiver(mReceiver, ifilt);

    // just for test purpose, should be deleted if not in test procedure.
    Intent service = new Intent(this, DeviceDicoverService.class);
    startService(service);

    wifii = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wInfo = wifii.getConnectionInfo();
}

From source file:cn.edu.zju.bme319.cordova.ExtraInfo.java

    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) 
            throws JSONException {
        Activity activity = this.cordova.getActivity();
        context = (Context) this.context;
      /* w  w w.  ja va  2 s  .c o m*/
       // Register for broadcasts when a device is discovered
      IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
      context.registerReceiver(mReceiver, filter);
      
      
      // Register for broadcasts when discovery starts
      filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
      context.registerReceiver(mReceiver, filter);

      
      // Register for broadcasts when discovery has finished
      filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
      context.registerReceiver(mReceiver, filter);  
      
             
      // Register for broadcasts when connectivity state changes
      filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
      context.registerReceiver(mReceiver, filter);  
      
      Looper.prepare();

      found_devices = new ArrayList<BluetoothDevice>(); 
      
        if (btadapter == null) {
          btadapter = BluetoothAdapter.getDefaultAdapter();
        }

        if (action.equals("getExtra")) {
   
           callbackContext.success("123");
            return true;
        }
        else if (ACTION_DISCOVER_DEVICES.equals(action)) {
           try {
            
            Log.d("BluetoothPlugin", "We're in "+ACTION_DISCOVER_DEVICES);
            
            found_devices.clear();
            discovering=true;
            
              if (btadapter.isDiscovering()) {
                 btadapter.cancelDiscovery();
              }
              
              Log.i("BluetoothPlugin","Discovering devices...");        
            btadapter.startDiscovery();      
            
            while (discovering){}
            
            String devicesFound=null;
            int count=0;
            devicesFound="[";
            for (BluetoothDevice device : found_devices) {
               Log.i("BluetoothPlugin",device.getName() + " "+device.getAddress()+" "+device.getBondState());
               if ((device.getName()!=null) && (device.getBluetoothClass()!=null)){
                  devicesFound = devicesFound + " { \"name\" : \"" + device.getName() + "\" ," +
                        "\"address\" : \"" + device.getAddress() + "\" ," +
                     "\"class\" : \"" + device.getBluetoothClass().getDeviceClass() + "\" }";
                  if (count<found_devices.size()-1) devicesFound = devicesFound + ",";
               }else Log.i("BluetoothPlugin",device.getName() + " Problems retrieving attributes. Device not added ");
               count++;
            }   
            
            devicesFound= devicesFound + "] ";            
            
            Log.d("BluetoothPlugin - "+ACTION_DISCOVER_DEVICES, "Returning: "+ devicesFound);
            callbackContext.success(devicesFound);
            //result = new PluginResult(Status.OK, devicesFound);
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_DISCOVER_DEVICES, "Got Exception "+ Ex.getMessage());
            callbackContext.error("discoveryError");
            //result = new PluginResult(Status.ERROR);
         }
         

//         try {
//            
//            Log.d("BluetoothPlugin", "We're in "+ACTION_DISCOVER_DEVICES);
//
//            // Create a BroadcastReceiver for ACTION_FOUND
////            final BroadcastReceiver mReceiver = new BroadcastReceiver() {
////                public void onReceive(Context context, Intent intent) {
////                    String action = intent.getAction();
////                    // When discovery finds a device
////                    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
////                        // Get the BluetoothDevice object from the Intent
////                        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
////                        // Add the name and address to an array adapter to show in a ListView
////                        mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
////                    }
////                }
////            };
////            // Register the BroadcastReceiver
////            IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
////            registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
////            
////             // ??
////              if (btadapter.isDiscovering()) {
////                 btadapter.cancelDiscovery();
////                 Log.d("BluetoothPlugin", "We're in "+"12");
////              }
////              //?
////              Log.d("BluetoothPlugin", "We're in "+"1234");
////              btadapter.startDiscovery();
////              Log.d("BluetoothPlugin", "We're in "+"123456");
////               
////            found_devices.clear();
////            //discovering=true;
////            
////              //if (btadapter.isDiscovering()) {
////              //   btadapter.cancelDiscovery();
////              //}
////              
////            SendCommand(0);
////            
////              Log.i("BluetoothPlugin","Discovering devices...");        
////            //btadapter.startDiscovery();   
////            
////            while (discovering){}
////            
////            String devicesFound=null;
////            int count=0;
////            devicesFound="[";
////            for (BluetoothDevice device : found_devices) {
////               Log.i("BluetoothPlugin",device.getName() + " "+device.getAddress()+" "+device.getBondState());
////               if ((device.getName()!=null) && (device.getBluetoothClass()!=null)){
////                  devicesFound = devicesFound + " { \"name\" : \"" + device.getName() + "\" ," +
////                        "\"address\" : \"" + device.getAddress() + "\" ," +
////                     "\"class\" : \"" + device.getBluetoothClass().getDeviceClass() + "\" }";
////                  if (count<found_devices.size()-1) devicesFound = devicesFound + ",";
////               }else Log.i("BluetoothPlugin",device.getName() + " Problems retrieving attributes. Device not added ");
////               count++;
////            }   
////            
////            devicesFound= devicesFound + "] ";            
////            
////            Log.d("BluetoothPlugin - "+ACTION_DISCOVER_DEVICES, "Returning: "+ devicesFound);
////            callbackContext.success(devicesFound);
//            //result = new PluginResult(Status.OK, devicesFound);
//            return true;
//         } catch (Exception Ex) {
//            Log.d("BluetoothPlugin - "+ACTION_DISCOVER_DEVICES, "Got Exception "+ Ex.getMessage());
//            //result = new PluginResult(Status.ERROR);
//            callbackContext.error("discoverError");
//            return false;
//         }
         
      
      } else    if (ACTION_IS_BT_ENABLED.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_IS_BT_ENABLED);
            
            boolean isEnabled = btadapter.isEnabled();
            
            Log.d("BluetoothPlugin - "+ACTION_IS_BT_ENABLED, "Returning "+ "is Bluetooth Enabled? "+isEnabled);
            callbackContext.success(""+isEnabled);
            //result = new PluginResult(Status.OK, isEnabled);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_IS_BT_ENABLED, "Got Exception "+ Ex.getMessage());
            callbackContext.error("isBTEnabledError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
         
      } else    if (ACTION_ENABLE_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_ENABLE_BT);
            
            boolean enabled = false;
            
            Log.d("BluetoothPlugin", "Enabling Bluetooth...");
            
            if (btadapter.isEnabled())
            {
              enabled = true;
            } else {
              enabled = btadapter.enable();
            }

            
            Log.d("BluetoothPlugin - "+ACTION_ENABLE_BT, "Returning "+ "Result: "+enabled);
            callbackContext.success("" + enabled);
            //result = new PluginResult(Status.OK, enabled);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_ENABLE_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("EnableBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }         
         
      } else    if (ACTION_DISABLE_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_DISABLE_BT);
            
            boolean disabled = false;
            
            Log.d("BluetoothPlugin", "Disabling Bluetooth...");
            
            if (btadapter.isEnabled())
            {
               disabled = btadapter.disable();
            } else {
               disabled = true;
            }            
                        
            Log.d("BluetoothPlugin - "+ACTION_DISABLE_BT, "Returning "+ "Result: "+disabled);
            callbackContext.success("" + disabled);
            //result = new PluginResult(Status.OK, disabled);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_DISABLE_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("DisableBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
               
      } else    if (ACTION_PAIR_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_PAIR_BT);
            
            String addressDevice = args.getString(0);
            
            if (btadapter.isDiscovering()) {
                 btadapter.cancelDiscovery();
              }

            BluetoothDevice device = btadapter.getRemoteDevice(addressDevice);
            boolean paired = false;
                     
            Log.d("BluetoothPlugin","Pairing with Bluetooth device with name " + device.getName()+" and address "+device.getAddress());
                   
            try {
               Method m = device.getClass().getMethod("createBond");
               paired = (Boolean) m.invoke(device);               
            } catch (Exception e) 
            {
               e.printStackTrace();
            }  
            
            
            Log.d("BluetoothPlugin - "+ACTION_PAIR_BT, "Returning "+ "Result: "+paired);
            callbackContext.success("" + paired);
            //result = new PluginResult(Status.OK, paired);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_PAIR_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("pairBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
         
                  
      } else    if (ACTION_UNPAIR_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_UNPAIR_BT);
            
            String addressDevice = args.getString(0);
            
            if (btadapter.isDiscovering()) {
                 btadapter.cancelDiscovery();
              }

            BluetoothDevice device = btadapter.getRemoteDevice(addressDevice);
            boolean unpaired = false;
                     
            Log.d("BluetoothPlugin","Unpairing Bluetooth device with " + device.getName()+" and address "+device.getAddress());
                   
            try {
               Method m = device.getClass().getMethod("removeBond");
               unpaired = (Boolean) m.invoke(device);               
            } catch (Exception e) 
            {
               e.printStackTrace();
            }  
            
            
            Log.d("BluetoothPlugin - "+ACTION_UNPAIR_BT, "Returning "+ "Result: "+unpaired);
            callbackContext.success("" + unpaired);
            //result = new PluginResult(Status.OK, unpaired);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_UNPAIR_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("unpairBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
                     
      } else    if (ACTION_LIST_BOUND_DEVICES.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_LIST_BOUND_DEVICES);
            
            Log.d("BluetoothPlugin","Getting paired devices...");
            //?
            Set<BluetoothDevice> pairedDevices = btadapter.getBondedDevices();
            int count =0;   
            String resultBoundDevices="[ ";
            if (pairedDevices.size() > 0) {               
               for (BluetoothDevice device : pairedDevices) 
               {                  
                  Log.i("BluetoothPlugin",device.getName() + " "+device.getAddress()+" "+device.getBondState());
                  
                  if ((device.getName()!=null) && (device.getBluetoothClass()!=null)){
                     resultBoundDevices = resultBoundDevices + " { \"name\" : \"" + device.getName() + "\" ," +
                           "\"address\" : \"" + device.getAddress() + "\" ," +
                           "\"class\" : \"" + device.getBluetoothClass().getDeviceClass() + "\" }";
                      if (count<pairedDevices.size()-1) resultBoundDevices = resultBoundDevices + ",";                  
                  } else Log.i("BluetoothPlugin",device.getName() + " Problems retrieving attributes. Device not added ");
                   count++;
                }             
               
            }
            
            resultBoundDevices= resultBoundDevices + "] ";
            
            Log.d("BluetoothPlugin - "+ACTION_LIST_BOUND_DEVICES, "Returning "+ resultBoundDevices);
            callbackContext.success("" + resultBoundDevices);
            //result = new PluginResult(Status.OK, resultBoundDevices);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_LIST_BOUND_DEVICES, "Got Exception "+ Ex.getMessage());
            callbackContext.error("resultBoundDevicesError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }   
            
         
      } else    if (ACTION_STOP_DISCOVERING_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_STOP_DISCOVERING_BT);
            
            boolean stopped = true;
            
            Log.d("BluetoothPlugin", "Stop Discovering Bluetooth Devices...");
            
            if (btadapter.isDiscovering())
            {
               Log.i("BluetoothPlugin","Stop discovery...");   
               stopped = btadapter.cancelDiscovery();
                 discovering=false;
            }            
            
         
            Log.d("BluetoothPlugin - "+ACTION_STOP_DISCOVERING_BT, "Returning "+ "Result: "+stopped);
            callbackContext.success("" + stopped);
            //result = new PluginResult(Status.OK, stopped);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_STOP_DISCOVERING_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("stoppedError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
         
         
      } else    if (ACTION_IS_BOUND_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_IS_BOUND_BT);
            String addressDevice = args.getString(0);
            BluetoothDevice device = btadapter.getRemoteDevice(addressDevice);
            Log.i("BluetoothPlugin","BT Device in state "+device.getBondState());   
            
            boolean state = false;
            
            if (device!=null && device.getBondState()==12) 
               state =  true;
            else
               state = false;
            
            Log.d("BluetoothPlugin","Is Bound with " + device.getName()+" - address "+device.getAddress());                         
            
            Log.d("BluetoothPlugin - "+ACTION_IS_BOUND_BT, "Returning "+ "Result: "+state);
            callbackContext.success("" + state);
            //result = new PluginResult(Status.OK, state);
            return true;   
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_IS_BOUND_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("boundBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }      
      
      
      } else if(ACTION_BT_CONNECT.equals(action)){
         try
         {
            Log.d("BluetoothPlugin", "We're in "+ACTION_BT_CONNECT);
            deviceAddress = "8C:DE:52:99:26:23";
            Log.d("BluetoothPlugin", "We're in "+deviceAddress);
            BluetoothDevice device = btadapter.getRemoteDevice(deviceAddress);
            
            //m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
            //bluetoothSocket = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));
            //SendCommand(0);
            // ??socket
            try {
               bluetoothSocket = device.createRfcommSocketToServiceRecord(UUID
                     .fromString(MY_UUID));
            } catch (IOException e) {
               //Toast.makeText(this, "?", Toast.LENGTH_SHORT).show();
            }
            bluetoothSocket.connect();
            sendCommandFlag = 0;
            SendCommand(sendCommandFlag);
            
            
            
            if(bluetoothSocket.isConnected())
            {
               this.isConnection = true;
               String str = "";
               // 
               try {
                  inputStream = bluetoothSocket.getInputStream(); // ???
                  str = ""+1;
               } catch (IOException e) {
                  //Toast.makeText(this, "??", Toast.LENGTH_SHORT).show();
                  //return;
                  str=""+2;
               }
               if (bThread == false) {
                  ReadThread.start();
                  bThread = true;
                  str = ""+3;
               } else {
                  bRun = true;
                  str = ""+4;
               }
               
               //result = new PluginResult(Status.OK, str);
                //result.setKeepCallback(true);
                    // callbackContext.sendPluginResult(result);
               callbackContext.success("" + str);
            }
            else {
               //result = new PluginResult(Status.OK, "failure");
               callbackContext.error("Could not connect to ");

            }
            return true;
         } catch (Exception Ex)
         {
            // TODO: handle exception
            Log.d("BluetoothPlugin - "+ACTION_BT_CONNECT, "Got Exception "+ Ex.getMessage());
            //result = new PluginResult(Status.ERROR);
            callbackContext.error("Could not connect to ");
            return false;
         }
      }else if(ACTION_BT_GETDATA.equals(action)){
         try
         {
            Log.d("BluetoothPlugin", "We're in "+ACTION_BT_GETDATA);
            sendCommandFlag = 1;
            SendCommand(sendCommandFlag);   
//            if (bluetoothSocket != null) {
//                  if(bluetoothSocket.isConnected()){
//                     SendCommand(1);   
//                  }
//            }
//               
            //result = new PluginResult(Status.OK, spoValue);
            Log.v("Get1 ", returnBTData);
            while(returnBTData == "")
            {
               Log.v("Get2 ", returnBTData);
            }
            Log.v("Get3 ", returnBTData);
            callbackContext.success("" + returnBTData);
            //ReadThread.cancel();
            
            bluetoothSocket.close();
            bluetoothSocket = null;
            
            return true;
         } catch (Exception Ex)
         {
            // TODO: handle exception
            Log.d("BluetoothPlugin - "+ACTION_BT_GETDATA, "Got Exception "+ Ex.getMessage());
            callbackContext.error("" + "getDataError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
      }
      
      else {
//         result = new PluginResult(Status.INVALID_ACTION);
//         Log.d("BluetoothPlugin", "Invalid action : "+action+" passed");
//         return result;
         callbackContext.error("" + "actionError");
      }
        return false;
    }

From source file:com.evothings.BLE.java

/**
* Called when the WebView does a top-level navigation or refreshes.
*
* Plugins should stop any long-running processes and clean up internal state.
*
* Does nothing by default.// ww w . j a  v  a  2 s  .  c o m
*
* Our version should stop any ongoing scan, and close any existing connections.
*/
@Override
public void onReset() {
    if (mScanCallbackContext != null) {
        BluetoothAdapter a = BluetoothAdapter.getDefaultAdapter();
        a.stopLeScan(this);
        mScanCallbackContext = null;
    }
    if (mGatt != null) {
        Iterator<GattHandler> itr = mGatt.values().iterator();
        while (itr.hasNext()) {
            GattHandler gh = itr.next();
            if (gh.mGatt != null)
                gh.mGatt.close();
        }
        mGatt.clear();
    }
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.activities.SensorSettingsActivity.java

private void openSelectDeviceDialog() {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter != null) {
        BluetoothDevice[] mAllBondedDevices = (BluetoothDevice[]) mBluetoothAdapter.getBondedDevices()
                .toArray(new BluetoothDevice[0]);

        int mDeviceIndex = 0;
        if (mAllBondedDevices.length > 0) {
            int deviceCount = mAllBondedDevices.length;
            String[] deviceNames = new String[deviceCount];
            for (int i = 0; i < deviceCount; i++) {
                BluetoothDevice device = mAllBondedDevices[i];
                deviceNames[i] = device.getName() + "\n|" + device.getAddress();
                if (deviceMacAdd.equals(device.getAddress())) {
                    mDeviceIndex = i;//from   www.j  a va2s . com
                }
            }
            DialogFragment deviceDialog = new SelectDeviceDialogFragment();
            Bundle args = new Bundle();
            args.putStringArray("names", deviceNames);
            args.putInt("position", mDeviceIndex);
            args.putBoolean("device", true);
            deviceDialog.setArguments(args);
            getFragmentManager().beginTransaction();
            deviceDialog.show(getSupportFragmentManager().beginTransaction(), "deviceDialog");
        }
    }
}

From source file:com.example.slidingmenuexample.ui.NXTRemoteControl.java

/** Called when the activity is first created. */
@SuppressWarnings("deprecation")
@Override/*from w ww  .j  a  v  a2 s . c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    readPreferences(prefs, null);
    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");
        }
    }

    mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
            "NXT Remote Control");

    if (!NO_BT) {
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

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

    setupUI();

    mNXTTalker = new NXTTalker(mHandler);

    pagelist = getSlidingMenu();
    pagelist.setShadowDrawable(R.drawable.shadow);
    pagelist.setBehindOffset(600);
    pagelist.setShadowWidth(15);
    pagelist.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setIcon(R.drawable.ic_launcher);

    if (savedInstanceState != null)
        mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
    if (mContent == null)
        mContent = new NXTRemoteControlView();

    setContentView(R.layout.content_frame);
    getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, mContent).commit();

    setBehindContentView(R.layout.menu_frame);
    getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame, new MenuListPages()).commit();

    setSlidingActionBarEnabled(true);
}

From source file:com.pairbluetooth.mariachiio.dagorik.pairbluetooth.test_bluetooth.test_bluetooth.utils.BlueDroid.java

/**
 * Cria uma intncia da classe BlueDroid.
 *///from ww  w.j a va  2  s  . c  o m
public BlueDroid(Context context, ConnectionDevice device, ConnectionSecure type) {
    mContext = context;
    mConnectionDevice = device;
    mConnectionSecure = type;
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
}

From source file:jp.gr.java_conf.piropiroping.bluetoothcommander.MainActivity.java

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

    // Set up the window layout
    setContentView(R.layout.activity_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();
        return;
    }
    commandLayout = (LinearLayout) findViewById(R.id.command_layout);
    savedCommand = new ArrayList();
    plusButton = (ImageButton) findViewById(R.id.plus_button);
    plusButton.setImageResource(R.drawable.plus_button);

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

}

From source file:org.apache.cordova.sipkita.BluetoothPrinter.java

boolean findBT(CallbackContext callbackContext, String name) {
    try {//from   w w  w  .  j  a  va 2  s. com
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        bluetoothPort = BluetoothPort.getInstance();
        if (mBluetoothAdapter == null) {
            Log.e(LOG_TAG, "No bluetooth adapter available");
        }
        if (!mBluetoothAdapter.isEnabled()) {
            Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            this.cordova.getActivity().startActivityForResult(enableBluetooth, 0);
        }
        Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
        if (pairedDevices.size() > 0) {
            for (BluetoothDevice device : pairedDevices) {
                // MP300 is the name of the bluetooth printer device
                if (device.getName().equalsIgnoreCase(name)) {
                    mmDevice = device;
                    return true;
                }
            }
        }
        Log.d(LOG_TAG, "Bluetooth Device Found: " + mmDevice.getName());
    } catch (Exception e) {
        String errMsg = e.getMessage();
        Log.e(LOG_TAG, errMsg);
        e.printStackTrace();
        callbackContext.error(errMsg);
    }
    return false;
}

From source file:de.schildbach.litecoinwallet.ui.RequestCoinsFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractBindServiceActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.wallet = application.getWallet();
    this.prefs = PreferenceManager.getDefaultSharedPreferences(activity);
    this.loaderManager = getLoaderManager();
    this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}

From source file:com.sorin.cloudcog.car.obd2.SilverBluetoothChatActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (D)//from   w  w  w  .  j  a  v  a 2 s .c  om
        Log.e(TAG, "+++ ON CREATE +++");

    // Set up the window layout
    setContentView(R.layout.car_pager_main_silver);
    // toast message at begining of activity start
    Toast.makeText(this, "Silver Light Style OBD2 data console", Toast.LENGTH_SHORT).show();
    mSilverAdapter = new CarTabFragmentHandlerSilver(getSupportFragmentManager());
    mSilverPager = (ViewPager) findViewById(R.id.pager_silver);
    mSilverPager.setAdapter(mSilverAdapter);

    mSilverIndicator = (TitlePageIndicator) findViewById(R.id.indicator_silver);
    mSilverIndicator.setViewPager(mSilverPager);

    // 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;
    }
    // When shacked it will return to main activity initialization
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mShakeDetector = new ShakeDetectorActivity();
    mShakeDetector.setOnShakeListener(new OnShakeListener() {
        // shake handler
        @Override
        public void onShake(int count) {

            SilverBluetoothChatActivity.this.finish();

        }
    });
}