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.bushstar.htmlcoin_android_wallet.ui.SendCoinsFragment.java

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

    setRetainInstance(true);//w ww.  j a  v  a 2s . co m
    setHasOptionsMenu(true);

    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;
        final String mimeType = intent.getType();

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && "htmlcoin".equals(scheme)) {
            initStateFromHTMLcoinUri(intentUri);
        } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(PaymentProtocol.MIMETYPE_PAYMENTREQUEST,
                    ndefMessage);
            initStateFromPaymentRequest(mimeType, ndefMessagePayload);
        } else if ((Intent.ACTION_VIEW.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final byte[] paymentRequest = HTMLcoinIntegration.paymentRequestFromIntent(intent);

            if (intentUri != null)
                initStateFromIntentUri(mimeType, intentUri);
            else if (paymentRequest != null)
                initStateFromPaymentRequest(mimeType, paymentRequest);
            else
                throw new IllegalArgumentException();
        } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) {
            initStateFromIntentExtras(intent.getExtras());
        } else {
            updateStateFrom(PaymentIntent.blank());
        }
    }
}

From source file:com.woollysammoth.nubit_android_wallet.ui.SendCoinsFragment.java

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

    setRetainInstance(true);/*w w  w.  j a  v  a 2  s.  c  o  m*/
    setHasOptionsMenu(true);

    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;
        final String mimeType = intent.getType();

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && "ppcoin".equals(scheme)) {
            initStateFromNubitUri(intentUri);
        } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(PaymentProtocol.MIMETYPE_PAYMENTREQUEST,
                    ndefMessage);
            initStateFromPaymentRequest(mimeType, ndefMessagePayload);
        } else if ((Intent.ACTION_VIEW.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final byte[] paymentRequest = NubitIntegration.paymentRequestFromIntent(intent);

            if (intentUri != null)
                initStateFromIntentUri(mimeType, intentUri);
            else if (paymentRequest != null)
                initStateFromPaymentRequest(mimeType, paymentRequest);
            else
                throw new IllegalArgumentException();
        } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) {
            initStateFromIntentExtras(intent.getExtras());
        } else {
            updateStateFrom(PaymentIntent.blank());
        }
    }
}

From source file:org.apache.cordova.plugin.BluetoothPlugin2.java

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
        throws JSONException {

    logDbg("Action: " + action);

    if (ACTION_IS_SUPPORTED.equals(action)) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, m_bluetoothAdapter != null));
        return true;
    } else if (m_bluetoothAdapter == null) {
        String msg = "Bluetooth is not supported !";
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, msg));
        logErr(msg);//from   w  ww .  j  a  va 2 s  . co  m
        return true;
    } else if (ACTION_ENABLE.equals(action)) {
        this.callback_enable = callbackContext;
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        if (!m_bluetoothAdapter.isEnabled()) {
            this.cordova.startActivityForResult(this, new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                    this.REQUEST_CODE_ENABLE);
        }
        callbackContext.sendPluginResult(pluginResult);
        return true;
    } else if (ACTION_DISABLE.equals(action)) {
        PluginResult pluginResult;
        if (!m_bluetoothAdapter.disable()
                && !(m_bluetoothAdapter.getState() == BluetoothAdapter.STATE_TURNING_OFF
                        || m_bluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF)) {
            pluginResult = new PluginResult(PluginResult.Status.ERROR);
        } else {
            pluginResult = new PluginResult(PluginResult.Status.OK);
        }
        callbackContext.sendPluginResult(pluginResult);
        return true;
    } else if (ACTION_IS_ENABLED.equals(action)) {
        boolean b = m_bluetoothAdapter.isEnabled();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, b));
        return true;
    } else if (ACTION_GETADDRESS.equals(action)) {
        String address = m_bluetoothAdapter.getAddress();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, address));
        return true;
    } else if (ACTION_GETNAME.equals(action)) {
        String name = m_bluetoothAdapter.getName();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, name));
        return true;
    } else if (ACTION_REQUEST_DISCOVERABLE.equals(action)) {
        final int duration = args.getInt(0);
        this.callback_discoverable = callbackContext;
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, duration);
        this.cordova.startActivityForResult(this, intent, this.REQUEST_CODE_DISCOVERABLE);
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    } else if (ACTION_STARTDISCOVERY.equals(action)) {
        this.callback_discovery = callbackContext;
        m_discoveredDevices = new JSONArray();
        // be sure there are no ongoing discovery
        m_bluetoothAdapter.cancelDiscovery();
        if (!m_bluetoothAdapter.startDiscovery()) {
            String msg = "Unable to start discovery";
            logErr(msg);
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, msg));
        } else {
            PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
            pluginResult.setKeepCallback(true);
            callbackContext.sendPluginResult(pluginResult);
        }
        return true;
    } else if (ACTION_CANCELDISCOVERY.equals(action)) {
        if (m_bluetoothAdapter.cancelDiscovery())
            callbackContext.success();
        else
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
        return true;
    } else if (ACTION_GETBONDEDDEVICES.equals(action)) {
        JSONArray bondedDevices = new JSONArray();
        Set<BluetoothDevice> bondSet = m_bluetoothAdapter.getBondedDevices();
        for (Iterator<BluetoothDevice> it = bondSet.iterator(); it.hasNext();) {
            BluetoothDevice bluetoothDevice = (BluetoothDevice) it.next();
            JSONObject deviceInfo = new JSONObject();
            deviceInfo.put("name", bluetoothDevice.getName());
            deviceInfo.put("address", bluetoothDevice.getAddress());
            deviceInfo.put("isBonded", true);
            bondedDevices.put(deviceInfo);
        }
        callbackContext.success(bondedDevices);
        return true;
    } else if (ACTION_FETCHUUIDS.equals(action)) {
        final String address = args.getString(0);
        this.callback_uuids = callbackContext;

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            String msg = "Not supported, minimum SDK version is :" + Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
            logErr(msg);
            callbackContext.error(msg);
            return true;
        }
        try {
            logDbg("Listing UUIDs for : " + address);
            // Fetch UUIDs from bluetooth device
            BluetoothDevice bluetoothDevice = m_bluetoothAdapter.getRemoteDevice(address);
            // min api 15 !!!
            Method m = bluetoothDevice.getClass().getMethod("fetchUuidsWithSdp", (Class[]) null);
            m.invoke(bluetoothDevice, (Object[]) null);
            PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
            pluginResult.setKeepCallback(true);
            callbackContext.sendPluginResult(pluginResult);
        } catch (Exception e) {
            logErr(e.toString() + " / " + e.getMessage());
            callbackContext.error(e.getMessage());
        }
        return true;
    } else if (ACTION_CONNECT.equals(action)) {
        final String address = args.getString(0);
        final String uuid = args.getString(1);
        final boolean secure = args.getBoolean(2);
        this.callback_connect = callbackContext;
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                BluetoothSocket socket = null;
                try {
                    logDbg("Connecting...");
                    // Cancel discovery because it will slow down the connection
                    if (m_bluetoothAdapter.isDiscovering())
                        m_bluetoothAdapter.cancelDiscovery();

                    //JWC adding
                    /*
                            
                    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address); //"74:45:8A:B2:4E:9A"); 
                    //Method m = device.getClass().getMethod("createInsecureRfcommSocket", 
                    //      new Class[] { int.class }); 
                    //socket = (BluetoothSocket)m.invoke(device, Integer.valueOf(1)); 
                    socket = device.createRfcommSocketToServiceRecord(java.util.UUID.fromString(uuid));
                    */
                    //////

                    System.out.println("BluetoothPlugin2.ACTION_CONNECT  address=" + address + ", uuid=" + uuid
                            + ", secure=" + secure);
                    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address); //"74:45:8A:B2:4E:9A"); 
                    socket = device.createInsecureRfcommSocketToServiceRecord(java.util.UUID.fromString(uuid));

                    // for others devices its works with:
                    // Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});

                    // for galaxy tab 2 with:
                    //Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class});

                    //socket = (BluetoothSocket) m.invoke(device, 1);

                    socket.connect();

                    /////JWC  READ

                    System.out.println("BluetoothPlugin2 trying to read right away...");
                    final int socketId = 0; //args.getInt(0);
                    final int bufferSize = 512; //args.getInt(1);
                    //this.callback_read = callbackContext;
                    ReadThread readThread = new ReadThread(m_sockets.get(socketId), socketId, bufferSize);
                    readThread.start();
                    m_readThreads.add(readThread);
                    PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
                    pluginResult.setKeepCallback(true);
                    callbackContext.sendPluginResult(pluginResult);

                    ///////////////

                    /* JWC removing
                    BluetoothDevice bluetoothDevice = 
                          m_bluetoothAdapter.getRemoteDevice(
                      address);
                    if (secure) {
                       socket = connectSecureHelper(
                             bluetoothDevice, 
                             UUID.fromString(uuid));
                    }
                    else {
                       socket = connectInsecureHelper(
                             bluetoothDevice, 
                             UUID.fromString(uuid));
                    }
                    */
                } catch (Exception e) {
                    logErr(e.toString() + " / " + e.getMessage());
                    callback_connect.error(e.getMessage());
                }
                if (socket != null) {
                    logDbg("Connected");
                    m_sockets.add(socket);
                    int socketId = m_sockets.indexOf(socket);
                    callback_connect.sendPluginResult(new PluginResult(PluginResult.Status.OK, socketId));
                } else {
                    callback_connect.error(0);
                }
            }
        });
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    } else if (ACTION_DISCONNECT.equals(action)) {
        final int socketId = args.getInt(0);
        try {
            BluetoothSocket socket = m_sockets.get(socketId);
            logDbg("Close socket");
            socket.close();
            logDbg("Delete socket from list");
            m_sockets.remove(socketId);
            for (int i = 0; i < m_readThreads.size(); i++) {
                if (m_readThreads.get(i).socketId == socketId) {
                    m_readThreads.remove(i);
                    break;
                }
            }
            callbackContext.success();
        } catch (Exception e) {
            logErr(e.toString() + " / " + e.getMessage());
            callbackContext.error(e.getMessage());
        }
        return true;
    } else if (ACTION_LISTEN.equals(action)) {
        final String name = args.getString(0);
        final String uuid = args.getString(1);
        final boolean secure = args.getBoolean(2);
        System.out.println(
                "BluetoothPlugin2.ACTION_LISTEN  name=" + name + ", uuid=" + uuid + ", secure=" + secure);
        this.callback_listen = callbackContext;
        if (m_listenThread != null) {
            m_listenThread.cancel();
            m_listenThread = null;
        }
        m_listenThread = new ListenThread(this.cordova, name, UUID.fromString(uuid), secure);
        m_listenThread.start();
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    } else if (ACTION_CANCEL_LISTENING.equals(action)) {
        if (m_listenThread != null) {
            m_listenThread.cancel();
        }
        m_listenThread = null;
        callbackContext.success();
        return true;
    } else if (ACTION_READ.equals(action)) {
        final int socketId = args.getInt(0);
        final int bufferSize = args.getInt(1);
        System.out.println("BluetoothPlugin2.ACTION_READ  socketId=" + socketId + ", bufferSize=" + bufferSize);
        this.callback_read = callbackContext;
        ReadThread readThread = new ReadThread(m_sockets.get(socketId), socketId, bufferSize);
        readThread.start();
        m_readThreads.add(readThread);
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    } else if (ACTION_WRITE.equals(action)) {
        final int socketId = args.getInt(0);
        final JSONArray jsonArray = args.getJSONArray(1);
        try {
            OutputStream outputStream = m_sockets.get(socketId).getOutputStream();
            byte[] buffer = new byte[jsonArray.length()];
            for (int i = 0; i < jsonArray.length(); i++) {
                buffer[i] = (byte) jsonArray.getInt(i);
            }
            outputStream.write(buffer);
            callbackContext.success();
        } catch (Exception e) {
            logErr(e.toString() + " / " + e.getMessage());
            callbackContext.error(e.getMessage());
        }
        return true;
    }

    return false;
}

From source file:com.matthewmitchell.nubits_android_wallet.ui.SendCoinsFragment.java

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

    setRetainInstance(true);//from  w  ww  .jav a 2s  .c  o  m
    setHasOptionsMenu(true);

    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;
        final String mimeType = intent.getType();

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && "nu".equals(scheme)) {
            initStateFromNubitsUri(intentUri);
        } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(PaymentProtocol.MIMETYPE_PAYMENTREQUEST,
                    ndefMessage);
            initStateFromPaymentRequest(mimeType, ndefMessagePayload);
        } else if ((Intent.ACTION_VIEW.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final byte[] paymentRequest = NubitsIntegration.paymentRequestFromIntent(intent);

            if (intentUri != null)
                initStateFromIntentUri(mimeType, intentUri);
            else if (paymentRequest != null)
                initStateFromPaymentRequest(mimeType, paymentRequest);
            else
                throw new IllegalArgumentException();
        } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) {
            initStateFromIntentExtras(intent.getExtras());
        } else {
            updateStateFrom(PaymentIntent.blank());
        }
    }
}

From source file:com.hamradiocoin.wallet.ui.send.SendCoinsFragment.java

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

    setRetainInstance(true);// w  w w .j av a 2s. c o  m
    setHasOptionsMenu(true);

    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;
        final String mimeType = intent.getType();

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && CoinDefinition.coinURIScheme.equals(scheme)) {
            initStateFromBitcoinUri(intentUri);
        } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(PaymentProtocol.MIMETYPE_PAYMENTREQUEST,
                    ndefMessage);
            initStateFromPaymentRequest(mimeType, ndefMessagePayload);
        } else if ((Intent.ACTION_VIEW.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final byte[] paymentRequest = BitcoinIntegration.paymentRequestFromIntent(intent);

            if (intentUri != null)
                initStateFromIntentUri(mimeType, intentUri);
            else if (paymentRequest != null)
                initStateFromPaymentRequest(mimeType, paymentRequest);
            else
                throw new IllegalArgumentException();
        } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) {
            initStateFromIntentExtras(intent.getExtras());
        } else {
            updateStateFrom(PaymentIntent.blank());
        }
    }
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.SendCoinsFragment.java

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

    setRetainInstance(true);//from  w  w  w .  j  a  v  a 2 s. com
    setHasOptionsMenu(true);

    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;
        final String mimeType = intent.getType();

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && "ppcoin".equals(scheme)) {
            initStateFromPeercoinUri(intentUri);
        } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(PaymentProtocol.MIMETYPE_PAYMENTREQUEST,
                    ndefMessage);
            initStateFromPaymentRequest(mimeType, ndefMessagePayload);
        } else if ((Intent.ACTION_VIEW.equals(action))
                && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final byte[] paymentRequest = PeercoinIntegration.paymentRequestFromIntent(intent);

            if (intentUri != null)
                initStateFromIntentUri(mimeType, intentUri);
            else if (paymentRequest != null)
                initStateFromPaymentRequest(mimeType, paymentRequest);
            else
                throw new IllegalArgumentException();
        } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) {
            initStateFromIntentExtras(intent.getExtras());
        } else {
            updateStateFrom(PaymentIntent.blank());
        }
    }
}

From source file:com.sonymobile.dronecontrol.activity.MainActivity.java

private boolean verifyBluetooth() {
    boolean result = false;
    final BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter == null) {
        // Device does not support Bluetooth
    } else if (btAdapter.isEnabled()) {
        result = true;/*  ww  w.jav a2  s . com*/
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Bluetooth").setMessage(R.string.DG_TURN_ON_BT)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        btAdapter.enable();
                        dialog.dismiss();
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
    }
    return result;
}

From source file:com.t2.compassionMeditation.DeviceManagerActivity.java

@Override
protected void onResume() {
    super.onResume();

    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        this.bluetoothDisabledDialog.show();
    }//from   w w  w  .j  av  a2 s  . co m
    if (deviceListAdapter != null) {
        deviceListAdapter.reloadItems();
    }
}

From source file:com.github.vgoliveira.panificadora.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {

    case REQUEST_SELECT_DEVICE:
        //When the DeviceListActivity return, with the selected device address
        if (resultCode == Activity.RESULT_OK && data != null) {
            String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE);
            mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress);

            Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService);
            ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting");
            mService.connect(deviceAddress);

        }// w ww.  j  av  a2  s . c om
        break;
    case REQUEST_ENABLE_BT:
        // When the request to enable Bluetooth returns
        if (resultCode == Activity.RESULT_OK) {
            Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show();

        } else {
            // User did not enable Bluetooth or an error occurred
            Log.d(TAG, "BT not enabled");
            Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show();
            finish();
        }
        break;
    case MainActivity.REQUEST_SELECT_RECIPE:
        if (resultCode != Activity.RESULT_CANCELED) {
            value = null;
            bakery = (Bakery) data.getSerializableExtra("bakery");
            recipe = (Recipe) data.getSerializableExtra("recipe");

            value = bakery.setProgram(value);

            new AlertDialog.Builder(this).setTitle("Ateno").setMessage(
                    "Antes de continuar, cetifique-se que a bandeja foi inserida com todos os ingredientes.")
                    .setPositiveButton("Continuar", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //send program to the machine
                            mService.writeRXCharacteristic(value);
                        }
                    }).show();

            //register this operation in cloud
        }
        break;
    case MainActivity.REQUEST_FACEBOOK_LOGIN:
        Toast.makeText(MainActivity.this, "Return Facebook Login", Toast.LENGTH_SHORT).show();
        String name = data.getStringExtra("name");
        String fbId = data.getStringExtra("id");
        String email = data.getStringExtra("email");
        String gender = data.getStringExtra("gender");
        String ageRange = data.getStringExtra("age_range");
        Toast.makeText(MainActivity.this, "User name: " + name, Toast.LENGTH_SHORT).show();
        Toast.makeText(MainActivity.this, "Facebook id: " + fbId, Toast.LENGTH_SHORT).show();
        Toast.makeText(MainActivity.this, "User email: " + email, Toast.LENGTH_SHORT).show();
        Toast.makeText(MainActivity.this, "Gender: " + gender, Toast.LENGTH_SHORT).show();
        Toast.makeText(MainActivity.this, "Age range: " + ageRange, Toast.LENGTH_SHORT).show();

        break;
    default:
        Log.e(TAG, "wrong request code");
        break;
    }
}

From source file:org.imdea.panel.MainActivity.java

protected void onDestroy() {
    super.onDestroy();
    if (Global.mqtt) {
        mqttService.disconnect();/*w  w w.j av  a 2 s.c  o m*/
        stopService(new Intent(this, mqttService.class));
    }

    stopService(new Intent(this, BtService.class));

    Global.db.close();
    Global.db = null;
    try {
        unregisterReceiver(messageReceiver);
    } catch (Exception e) {
        Log.e("Main", "Error unregistering messageReceiver");
    }
    BluetoothAdapter.getDefaultAdapter().disable();

}