Air superiority for Android Apps

1,415 views

Published on

We live in a superconnected world, where 1.3 million Android devices are activated a day, and it is becoming more usual to see
users with one or even more Android devices. Seamlessly sharing data between devices might be what differentiate your app among its
competitors! Find out the potential you can unveil by getting the most of NFC, Bluetooth or WiFi Direct APIs.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,415
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
18
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Air superiority for Android Apps

  1. 1. SUPERIORIDAD AÉREAEN APLICACIONES ANDROID Saúl Díaz González saul@tuenti.com
  2. 2. Wi-Fi 802.11 N Near-Field Comm.Bluetooth 3.0 + HS
  3. 3. “¿Cómo mejorarlo? Le pondremos Bluetooth. ¡Todo es mejorcon Bluetooth!” -Sheldon Cooper
  4. 4. BúsquedaDescubrimiento Conectar Aceptar¡Emparejados!
  5. 5. Clases clave DescubrirBluetooth Bluetooth Adapter Device BluetoothCrear Adapter Conectar BluetoothBluetooth Aceptar Server Socket Socket
  6. 6. Activando el Bluetooth BLUETOOTH BLUETOOTH_ADMIN mBtAdapter = BluetoothAdapter.getDefaultAdapter(); mBtAdapter == null? SiIntent(BluetoothAdapter.ACTION_REQUEST_ENABLE);startActivityForResult(intent, REQUEST_ENABLE_BT);
  7. 7. Descubrimiento Cliente Servidor Intent(BluetoothAdapter. mBtAdapter.startDiscovery(); ACTION_REQUEST_DISCOVERABLE); Intent.putExtra(BluetoothAdapter. EXTRA_DISCOVERABLE_DURATION, 300); IntentFilter(BluetoothDevice. ACTION_FOUND); registerReceiver(mReceiver, filter); intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
  8. 8. Conexión Cliente ServidorbtDevice. mBtAdapter. createRfcommSocketToServiceRecord( listenUsingRfcommWithServiceRecord(NAME, MY_UUID); MY_UUID); clientSocket.connect(); serverSocket.accept(); in = socket.getInputStream(); out = socket.getOutputStream(); in.read(buffer) //Buffer is byte[] out.write(buffer)
  9. 9. “Cualquier tecnología lo suficientemente avanzada esindistinguible de la magia” -Arthur C. Clarke
  10. 10. NFC TagWrite Read Android Beam
  11. 11. NFC Data Exchange Format (NDEF)Record1 Record2 ... RecordNHeader PayloadIdentifier Length Type
  12. 12. Requisitos NFCUses Permission Intent Filter NFC android.nfc.action.NDEF_DISCOVERED
  13. 13. Leer un mensaje NDEFpublic 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 }}
  14. 14. Opciones de dispatchingClassic Intent NFC Foreground Android App Dispatch Dispatch Record mNfcAdapter. enableForegroundDispatch( ...); NdefRecord. createApplicationRecord( “com.example.nfc.beam”); mNfcAdapter. disableForegroundDispatch( this);
  15. 15. Escribir en una Tagprivate 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();}
  16. 16. Android Beampublic class BluetoothChat extends Activity implements CreateNdefMessageCallback{ @Override public NdefMessage createNdefMessage(NfcEvent event) { try { NdefRecord[] records = { createRecord() }; NdefMessage message = new NdefMessage(records); return message; } catch (UnsupportedEncodingException e) { //Handle error here } return null;}
  17. 17. Demo time!
  18. 18. “Chuck Norris puede estrangular a un hombre con el cablede una conexión Wi-Fi.” -Proverbio chino
  19. 19. 200x 28x 12x 1xBT 2.1 BT 3.0+HS WiFi 11g WiFi 11n
  20. 20. PeersGroup Owner
  21. 21. Requisitos Wi-Fi DirectIce Cream PermisosSandwich ACCESS_WIFI_STATE CHANGE_WIFI_STATE CHANGE_NETWORK_STATE INTERNET ACCESS_NETWORK_STATE
  22. 22. Con un receiver voy sobrado WIFI_STATE_CHANGED_ACTION WIFI_P2P_PEERS_CHANGED_ACTIONWIFI_P2P_CONNECTION_CHANGED_ACTION WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
  23. 23. Y esto es todo lo que hay que saber Listener Métodos Eventos connect(), onSuccess() ActionListener cancelConnect(),... onFailure() ChannelListener initialize() onChannelDisconnected()ConnectionInfoListener requestConnectInfo() onConnectionAvailable() GroupInfoListener requestGroupInfo() onGroupInfoAvailable() PeerListListener requestPeers() onPeersAvailable()
  24. 24. ¡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 } });
  25. 25. Mientras en el receiver...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... } }); }}
  26. 26. Frecuencias de llamadas abiertasWifiP2pDevice 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 }});
  27. 27. Superioridad aérea Sencillo Mágico
  28. 28. ¡Muchas gracias! Saúl Díaz González saul@tuenti.com @sefford

×