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:edu.missouri.bas.service.SensorService.java

@SuppressWarnings("deprecation")
@Override//  w  w  w.j ava  2 s .  c o  m
public void onCreate() {

    super.onCreate();
    Log.d(TAG, "Starting sensor service");
    mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
    soundsMap = new HashMap<Integer, Integer>();
    soundsMap.put(SOUND1, mSoundPool.load(this, R.raw.bodysensor_alarm, 1));
    soundsMap.put(SOUND2, mSoundPool.load(this, R.raw.voice_notification, 1));

    serviceContext = this;

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    bluetoothMacAddress = mBluetoothAdapter.getAddress();
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    //Get location manager
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    activityRecognition = new ActivityRecognitionScan(getApplicationContext());
    activityRecognition.startActivityRecognitionScan();

    mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    serviceWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorServiceLock");
    serviceWakeLock.acquire();

    //Initialize start time
    stime = System.currentTimeMillis();

    //Setup calendar object
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(stime);

    /*
     * Setup notification manager
     */

    notification = new Notification(R.drawable.icon2, "Recorded", System.currentTimeMillis());
    notification.defaults = 0;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent notifyIntent = new Intent(Intent.ACTION_MAIN);
    notifyIntent.setClass(this, MainActivity.class);

    /*
     * Display notification that service has started
     */
    notification.tickerText = "Sensor Service Running";
    PendingIntent contentIntent = PendingIntent.getActivity(SensorService.this, 0, notifyIntent,
            Notification.FLAG_ONGOING_EVENT);
    notification.setLatestEventInfo(SensorService.this, getString(R.string.app_name),
            "Recording service started at: " + cal.getTime().toString(), contentIntent);

    notificationManager.notify(SensorService.SERVICE_NOTIFICATION_ID, notification);

    // locationControl = new LocationControl(this, mLocationManager, 1000 * 60, 200, 5000);   

    IntentFilter activityResultFilter = new IntentFilter(XMLSurveyActivity.INTENT_ACTION_SURVEY_RESULTS);
    SensorService.this.registerReceiver(alarmReceiver, activityResultFilter);

    IntentFilter sensorDataFilter = new IntentFilter(SensorService.ACTION_SENSOR_DATA);
    SensorService.this.registerReceiver(alarmReceiver, sensorDataFilter);
    Log.d(TAG, "Sensor service created.");

    try {
        prepareIO();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    prepareAlarms();

    Intent startSensors = new Intent(SensorService.ACTION_START_SENSORS);
    this.sendBroadcast(startSensors);

    Intent scheduleCheckConnection = new Intent(SensorService.ACTION_SCHEDULE_CHECK);
    scheduleCheck = PendingIntent.getBroadcast(serviceContext, 0, scheduleCheckConnection, 0);
    mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime() + 1000 * 60 * 5, 1000 * 60 * 5, scheduleCheck);
    mLocationClient = new LocationClient(this, this, this);
}

From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {

    if (intent == null) {
        return START_STICKY;
    }/*from w w  w .  j a  v a 2  s . c o  m*/

    String action = intent.getAction();

    if (Intent.ACTION_BATTERY_CHANGED.equals(action) || Intent.ACTION_BATTERY_LOW.equals(action)
            || Intent.ACTION_BATTERY_OKAY.equals(action)) {
        // ????

        mHostBatteryManager.setBatteryRequest(intent);

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostBatteryProfile.PROFILE_NAME,
                null, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE);
        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostBatteryProfile.setAttribute(mIntent, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE);
            Bundle battery = new Bundle();
            HostBatteryProfile.setLevel(battery, mHostBatteryManager.getBatteryLevel());
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;
    } else if (Intent.ACTION_POWER_CONNECTED.equals(action)
            || Intent.ACTION_POWER_DISCONNECTED.equals(action)) {
        // ????

        mHostBatteryManager.setBatteryRequest(intent);

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostBatteryProfile.PROFILE_NAME,
                null, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE);

        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostBatteryProfile.setAttribute(mIntent, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE);
            Bundle charging = new Bundle();

            if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
                HostBatteryProfile.setCharging(charging, true);
            } else {
                HostBatteryProfile.setCharging(charging, false);
            }

            HostBatteryProfile.setBattery(mIntent, charging);
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;
    } else if (action.equals("android.intent.action.NEW_OUTGOING_CALL")) {
        // Phone

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostPhoneProfile.PROFILE_NAME, null,
                HostPhoneProfile.ATTRIBUTE_ON_CONNECT);

        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostPhoneProfile.setAttribute(mIntent, HostPhoneProfile.ATTRIBUTE_ON_CONNECT);
            Bundle phoneStatus = new Bundle();
            HostPhoneProfile.setPhoneNumber(phoneStatus, intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER));
            HostPhoneProfile.setState(phoneStatus, CallState.START);
            HostPhoneProfile.setPhoneStatus(mIntent, phoneStatus);
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)
            || WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        // Wifi

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostConnectProfile.PROFILE_NAME,
                null, HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE);

        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE);
            Bundle wifiConnecting = new Bundle();
            WifiManager wifiMgr = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
            HostConnectProfile.setEnable(wifiConnecting, wifiMgr.isWifiEnabled());
            HostConnectProfile.setConnectStatus(mIntent, wifiConnecting);
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;

    } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostConnectProfile.PROFILE_NAME,
                null, HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE);

        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE);
            Bundle bluetoothConnecting = new Bundle();
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            HostConnectProfile.setEnable(bluetoothConnecting, mBluetoothAdapter.isEnabled());
            HostConnectProfile.setConnectStatus(mIntent, bluetoothConnecting);
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;
    }
    return super.onStartCommand(intent, flags, startId);
}

From source file:cc.mintcoin.wallet.ui.SendCoinsFragment.java

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

    setHasOptionsMenu(true);/*  w w  w .j ava  2  s .  com*/

    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

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

From source file:com.lge.helloFriendsCamera.ConnectionActivity.java

/**
 * Ask permissions and start scan if all permissions are granted
 *//*from   w  w w  .j  a  v  a 2 s . c om*/
private void checkBleScanPermissionAndStartScan() {
    Log.d(TAG, "PERMISSION_REQUEST: BLUETOOTH AND ACCESS_FINE_LOCATION");
    int loc_permissionCheck = ContextCompat.checkSelfPermission(mContext,
            Manifest.permission.ACCESS_FINE_LOCATION);

    //Enable wifi
    if (!mWifiManager.isWifiEnabled())
        mWifiManager.setWifiEnabled(true);

    //Enable bt
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (!bluetoothAdapter.isEnabled()) {
        Log.d(TAG, "Request bluetooth enable");
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        return;
    }

    //Get permission (ACCESS_FINE_LOCATION)
    if (loc_permissionCheck != PackageManager.PERMISSION_GRANTED) {
        Log.d(TAG, "Request ACTION_FINE_LOCATION permission");
        ActivityCompat.requestPermissions((Activity) mContext,
                new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
        return;
    }

    startScanDevice();
}

From source file:mobisocial.musubi.ui.NearbyActivity.java

private void findBluetooth() {
    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        Intent bt = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(bt, RESULT_BT_ENABLE);
        return;/*www. ja va2 s  .c  o  m*/
    }

    // Create a BroadcastReceiver for ACTION_FOUND
    final IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);

    final BroadcastReceiver receiver = new BroadcastReceiver() {
        public void onReceive(final Context context, final Intent intent) {
            String action = intent.getAction();
            // When discovery finds a device
            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                new Thread() {
                    public void run() {
                        BluetoothBeacon.OnDiscovered discovered = new BluetoothBeacon.OnDiscovered() {
                            @Override
                            public void onDiscovered(final byte[] data) {
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            JSONObject obj = new JSONObject(new String(data));
                                            BJDNotImplementedException.except("bluetooth not implemented");
                                            //                                                mNearbyList.add(new NearbyFeed(NearbyActivity.this,
                                            //                                                        obj.getString("name"), Uri.parse(obj
                                            //                                                                .getString("dynuri"))));
                                            mAdapter.notifyDataSetChanged();
                                        } catch (JSONException e) {
                                            Log.e(TAG, "Error getting group info over bluetooth", e);
                                        }
                                    }
                                });
                            }
                        };
                        // Get the BluetoothDevice object from the Intent
                        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                        BluetoothBeacon.discover(NearbyActivity.this, device, discovered);
                    };
                }.start();
            }
            if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                unregisterReceiver(this);
            }
        }
    };

    registerReceiver(receiver, filter); // Don't forget to unregister during
                                        // onDestroy
    BluetoothAdapter.getDefaultAdapter().startDiscovery();
    Toast.makeText(this, "Scanning Bluetooth...", 500).show();
}

From source file:com.wordpress.bennthomsen.ble_uart_remote.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  w  w  . ja  va 2 s  .c o  m*/
        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;
    default:
        Log.e(TAG, "wrong request code");
        break;
    }
}

From source file:de.langerhans.wallet.ui.SendCoinsFragment.java

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

    setRetainInstance(true);/*www.  ja va2  s  .  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 && "dogecoin".equals(scheme)) {
            initStateFromBitcoinUri(intentUri);
        } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && com.google.dogecoin.protocols.payments.PaymentProtocol.MIMETYPE_PAYMENTREQUEST
                        .equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(
                    com.google.dogecoin.protocols.payments.PaymentProtocol.MIMETYPE_PAYMENTREQUEST,
                    ndefMessage);
            initStateFromPaymentRequest(mimeType, ndefMessagePayload);
        } else if ((Intent.ACTION_VIEW.equals(action))
                && com.google.dogecoin.protocols.payments.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.rimbit.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 .  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 && "rimbit".equals(scheme)) {
            initStateFromRimbitUri(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 = RimbitIntegration.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.mchp.android.PIC32_BTSK.PIC32_BTSK.java

@Override
public synchronized void onResume() {
    super.onResume();
    if (D)/*w w  w . jav  a2s  .co  m*/
        Log.e(TAG, "+ ON RESUME +");

    // Performing this check in onResume() covers the case in which BT was
    // not enabled during onStart(), so we were paused to enable it...
    // onResume() will be called when ACTION_REQUEST_ENABLE activity returns.
    if (mBluetoothService != null) {
        // Only if the state is STATE_NONE, do we know that we haven't started already
        if (mBluetoothService.getState() == BluetoothService.STATE_NONE) {
            // Start the Bluetooth service
            mBluetoothService.start();
        }

        // Reconnect last connected device
        if (mBluetoothService.getState() != BluetoothService.STATE_CONNECTED) {
            SharedPreferences settings = getSharedPreferences(PREF_DEVICE_ADDR, 0);
            mLastConnectedDeviceAddr = settings.getString(DEVICE_ADDR, null);

            if (mLastConnectedDeviceAddr != null) {
                BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
                // Get a set of currently paired devices
                Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
                for (BluetoothDevice device : pairedDevices) {
                    if (device.getAddress().equals(mLastConnectedDeviceAddr)) {
                        mBluetoothService.connect(device, false);
                        break;
                    }
                }
            }

        }
    }
}

From source file:com.bushstar.kobocoin_android_wallet.ui.SendCoinsFragment.java

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

    setRetainInstance(true);//from  ww  w  .  j  av a  2 s.  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 && "kobocoin".equals(scheme)) {
            initStateFromKobocoinUri(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 = KobocoinIntegration.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());
        }
    }
}