Air superiority for Android Apps
Upcoming SlideShare
Loading in...5
×
 

Air superiority for Android Apps

on

  • 1,375 views

We live in a superconnected world, where 1.3 million Android devices are activated a day, and it is becoming more usual to see ...

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.

Statistics

Views

Total Views
1,375
Views on SlideShare
1,367
Embed Views
8

Actions

Likes
2
Downloads
15
Comments
0

1 Embed 8

https://twitter.com 8

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Air superiority for Android Apps Air superiority for Android Apps Presentation Transcript

  • SUPERIORIDAD AÉREAEN APLICACIONES ANDROID Saúl Díaz González saul@tuenti.com
  • Wi-Fi 802.11 N Near-Field Comm.Bluetooth 3.0 + HS
  • “¿Cómo mejorarlo? Le pondremos Bluetooth. ¡Todo es mejorcon Bluetooth!” -Sheldon Cooper
  • BúsquedaDescubrimiento Conectar Aceptar¡Emparejados!
  • Clases clave DescubrirBluetooth Bluetooth Adapter Device BluetoothCrear Adapter Conectar BluetoothBluetooth Aceptar Server Socket Socket
  • Activando el Bluetooth BLUETOOTH BLUETOOTH_ADMIN mBtAdapter = BluetoothAdapter.getDefaultAdapter(); mBtAdapter == null? SiIntent(BluetoothAdapter.ACTION_REQUEST_ENABLE);startActivityForResult(intent, REQUEST_ENABLE_BT);
  • 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);
  • 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)
  • “Cualquier tecnología lo suficientemente avanzada esindistinguible de la magia” -Arthur C. Clarke
  • NFC TagWrite Read Android Beam
  • NFC Data Exchange Format (NDEF)Record1 Record2 ... RecordNHeader PayloadIdentifier Length Type
  • Requisitos NFCUses Permission Intent Filter NFC android.nfc.action.NDEF_DISCOVERED
  • 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 }}
  • Opciones de dispatchingClassic Intent NFC Foreground Android App Dispatch Dispatch Record mNfcAdapter. enableForegroundDispatch( ...); NdefRecord. createApplicationRecord( “com.example.nfc.beam”); mNfcAdapter. disableForegroundDispatch( this);
  • 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();}
  • 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;}
  • Demo time!
  • “Chuck Norris puede estrangular a un hombre con el cablede una conexión Wi-Fi.” -Proverbio chino
  • 200x 28x 12x 1xBT 2.1 BT 3.0+HS WiFi 11g WiFi 11n
  • PeersGroup Owner
  • Requisitos Wi-Fi DirectIce Cream PermisosSandwich ACCESS_WIFI_STATE CHANGE_WIFI_STATE CHANGE_NETWORK_STATE INTERNET ACCESS_NETWORK_STATE
  • Con un receiver voy sobrado WIFI_STATE_CHANGED_ACTION WIFI_P2P_PEERS_CHANGED_ACTIONWIFI_P2P_CONNECTION_CHANGED_ACTION WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
  • 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()
  • ¡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 } });
  • 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... } }); }}
  • 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 }});
  • Superioridad aérea Sencillo Mágico
  • ¡Muchas gracias! Saúl Díaz González saul@tuenti.com @sefford