Android Wi-Fi Manager and Bluetooth Connection

  • 4,291 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,291
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
125
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Android  Wi-­‐Fi  and  Bluetooth   Jussi  Pohjolainen  
  • 2. WI-­‐FI  MANAGER  
  • 3. WifiManager  •  WifiManager  is  able   –  List  current  configured  networks   –  Can  configure  the  current  ac?ve  wi-­‐fi  connec?on   –  Results  of  access  point  scans,  •  Needs   android.permission.ACCESS_WIFI_STATE  
  • 4. Show  Wi-­‐Fi  Informa?on  
  • 5. WifiManager’s  methods  •  addNetwork(WifiConfigura?on  wc)   –  Add  a  new  network  descrip?on  to  the  set  of   configured  networks.  •  disableNetwork(int  netId)   –  Disable  a  configured  network.    •  List<WifiConfigura?on>  getConfiguredNetworks()   –  Return  a  list  of  all  the  networks  configured  in  the   supplicant.  •  See:  hTp://developer.android.com/reference/ android/net/wifi/WifiManager.html  
  • 6. BLUETOOTH  API  
  • 7. Android  Bluetooth  API  •  Wirelessly  exchange  data  with  other   bluetooth  devices  •  Possibili?es   –  Scan  other  devices   –  Connect  to  other  devices  through  discovery   –  Transfer  data   –  Manage  mul?ple  connec?ons    
  • 8. Bluetooth  Permissions  •  In  order  to  use  bluetooth  features,  one  must   declare  at  least  one  of  the  following:     –  BLUETOOTH   •  Reques?ng,  accep?ng,  and  transferring  data   –  BLUETOOTH_ADMIN   •  Device  discovery  and  manipulate  bluetooth  sengs  
  • 9. Seng  Up  Bluetooth  
  • 10. Seng  Up  Bluetooth  
  • 11. Querying  Paired  Devices  
  • 12. Discovering  All  Devices  •  To  discover  use,  startDiscovery  from   BluetoothAdapter:   –  mBluetoothAdapter.startDiscovery();•  Will  return  boolean  value  if  the  discovering   started  ok.  •  Discovery  is  asynchronous  and  last  about  12   secs  •  When  devices  are  discovered  broadcast   happens…  
  • 13. Listening  to  Broadcasts  •  You  must  create  a  broadcast  receiver  that   listens  when  devices  are  discovered  •  Register   –  IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); –  registerReceiver(mReceiver, filter); –  // Dont forget to unregister during onDestroy  
  • 14. Broadcast  Receiver  // Create a BroadcastReceiver for ACTION_FOUNDprivate final BroadcastReceiver mReceiver = new BroadcastReceiver() {    public void onReceive(Context context, Intent intent) {        String action = intent.getAction();        // When discovery finds a device        if (BluetoothDevice.ACTION_FOUND.equals(action)) {            // Get the BluetoothDevice object from the Intent            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);            // Add the name and address to an array adapter to show in a ListView            mArrayAdapter.add(device.getName() + "n" + device.getAddress());        }    }};
  • 15. Connec?ng  •  You  must  have  a  client  and  a  server  •  Use  classes  BluetoothServerSocket  and   BluetoothSocket•  Connec?on  is  done  in  separate  thread  •  You  have  to  have  server  and  client  
  • 16. Server  
  • 17. Client