Download - Air superiority for Android Apps

Transcript
Page 1: Air superiority for Android Apps

SUPERIORIDAD AÉREAEN APLICACIONES ANDROID

Saúl Díaz Gonzá[email protected]

Page 2: Air superiority for Android Apps

Wi-Fi 802.11 N

Bluetooth 3.0 + HS

Near-Field Comm.

Page 3: Air superiority for Android Apps

“¿Cómo mejorarlo? Le pondremos Bluetooth. ¡Todo es mejor con Bluetooth!”

-Sheldon Cooper

Page 4: Air superiority for Android Apps

Búsqueda

Aceptar

Conectar

Descubrimiento

¡Emparejados!

Page 5: Air superiority for Android Apps

Conectar

Cre

arDescubrir

BluetoothAdapter

BluetoothDevice

BluetoothAdapter

BluetoothSocket

BluetoothServerSocket

Aceptar

Clases clave

Page 6: Air superiority for Android Apps

BLUETOOTHBLUETOOTH_ADMIN

mBtAdapter = BluetoothAdapter.getDefaultAdapter();

mBtAdapter == null?

Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);startActivityForResult(intent, REQUEST_ENABLE_BT);

Si

Activando el Bluetooth

Page 7: Air superiority for Android Apps

DescubrimientoCliente Servidor

mBtAdapter.startDiscovery();Intent(BluetoothAdapter.

ACTION_REQUEST_DISCOVERABLE);Intent.putExtra(BluetoothAdapter.

EXTRA_DISCOVERABLE_DURATION,300);

IntentFilter(BluetoothDevice.ACTION_FOUND);

registerReceiver(mReceiver, filter);

intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

Page 8: Air superiority for Android Apps

ConexiónCliente Servidor

mBtAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);

serverSocket.accept();

btDevice.createRfcommSocketToServiceRecord( MY_UUID);

clientSocket.connect();

in = socket.getInputStream();out = socket.getOutputStream();in.read(buffer) //Buffer is byte[]out.write(buffer)

Page 9: Air superiority for Android Apps

“Cualquier tecnología lo suficientemente avanzada es indistinguible de la magia”

-Arthur C. Clarke

Page 10: Air superiority for Android Apps

Android Beam

Write Read

NFC Tag

Page 11: Air superiority for Android Apps

Header Payload

Identifier Length Type

NFC Data Exchange Format (NDEF)

Record1 Record2 ... RecordN

Page 12: Air superiority for Android Apps

Requisitos NFC

NFC

Uses Permission Intent Filter

android.nfc.action.NDEF_DISCOVERED

Page 13: Air superiority for Android Apps

Leer un mensaje NDEF

public void onNewIntent(Intent intent) { if (NfcAdapter.ACTION_NDEF_DISCOVERED. equals(intent.getAction())) { Parcelable[] rawMsgs = intent.

getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);

NdefMessage[] msgs; if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } }

//Process Messages }}

Page 14: Air superiority for Android Apps

Opciones de dispatching

NFC ForegroundDispatch

Classic Intent Dispatch

Android AppRecord

mNfcAdapter.enableForegroundDispatch(...);

mNfcAdapter.disableForegroundDispatch(this);

NdefRecord.createApplicationRecord(“com.example.nfc.beam”);

Page 15: Air superiority for Android Apps

Escribir en una Tag

private void write(Tag tag) throws IOException, FormatException {

NdefRecord[] records = { createRecord() }; NdefMessage message = new NdefMessage(records);

// Get an instance of Ndef for the tag. Ndef ndef = Ndef.get(tag);

// Enable I/O ndef.connect();

// Write the message ndef.writeNdefMessage(message);

// Close the connection ndef.close();}

Page 16: Air superiority for Android Apps

Android Beam

public class BluetoothChat extends Activity implements CreateNdefMessageCallback{

@Overridepublic NdefMessage createNdefMessage(NfcEvent event) {

try {NdefRecord[] records = { createRecord() };NdefMessage message = new NdefMessage(records);

return message;} catch (UnsupportedEncodingException e) {

//Handle error here}return null;

}

Page 17: Air superiority for Android Apps

Demo time!

Page 18: Air superiority for Android Apps

“Chuck Norris puede estrangular a un hombre con el cable de una conexión Wi-Fi.”

-Proverbio chino

Page 19: Air superiority for Android Apps

BT 2.1 WiFi 11g WiFi 11n

1x

28x

200x

BT 3.0+HS

12x

Page 20: Air superiority for Android Apps

Group Owner

Peers

Page 21: Air superiority for Android Apps

Ice CreamSandwich

Permisos

ACCESS_WIFI_STATECHANGE_WIFI_STATE

CHANGE_NETWORK_STATEINTERNET

ACCESS_NETWORK_STATE

Requisitos Wi-Fi Direct

Page 22: Air superiority for Android Apps

WIFI_P2P_CONNECTION_CHANGED_ACTION

WIFI_STATE_CHANGED_ACTION WIFI_P2P_PEERS_CHANGED_ACTION

WIFI_P2P_THIS_DEVICE_CHANGED_ACTION

Con un receiver voy sobrado

Page 23: Air superiority for Android Apps

Listener Métodos Eventos

ActionListenerconnect(),

cancelConnect(),...onSuccess()onFailure()

ChannelListener initialize() onChannelDisconnected()

ConnectionInfoListener requestConnectInfo() onConnectionAvailable()

GroupInfoListener requestGroupInfo() onGroupInfoAvailable()

PeerListListener requestPeers() onPeersAvailable()

Y esto es todo lo que hay que saber

Page 24: Air superiority for Android Apps

¡Peer a la vista!

mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);

mChannel = mManager.initialize(this, getMainLooper(), null);mReceiver = new WiFiDirectBroadcastReceiver(mManager,mChannel,this); mManager.discoverPeers(channel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { //success logic }

@Override public void onFailure(int reasonCode) { //failure logic } });

Page 25: Air superiority for Android Apps

if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) { if (mManager != null) { mManager.requestPeers(mChannel, new PeerListListener(){

@Override public void onPeersAvailable(WifiP2pDeviceList list) { //Update Peer List, data model, etc... } }); }}

Mientras en el receiver...

Page 26: Air superiority for Android Apps

WifiP2pDevice device = new WifiP2pDevice();WifiP2pConfig config = new WifiP2pConfig();config.deviceAddress = device.deviceAddress;mManager.connect(mChannel, config, new ActionListener() {

@Override public void onSuccess() { //ready for connecting through a socket }

@Override public void onFailure(int reason) { //failure logic }});

Frecuencias de llamadas abiertas

Page 27: Air superiority for Android Apps

Superioridad aérea

Mágico

Sencillo

Page 28: Air superiority for Android Apps

¡Muchas gracias!Saúl Díaz González

[email protected]@sefford