+ All Categories
Home > Documents > Choose one of the available networks var availableNetworks =...

Choose one of the available networks var availableNetworks =...

Date post: 22-Dec-2015
Category:
Upload: julian-barrett
View: 223 times
Download: 0 times
Share this document with a friend
15
Lillian Tseng Program Manager Get your apps connected with networking APIs Get your apps connected with networking APIs 2-86
Transcript
Page 1: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

Lillian TsengProgram ManagerGet your apps connected with networking APIs

Get your apps connected with networking APIs

2-86

Page 2: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

Problem & prior solutionsWhat’s new in Windows 10Sample codeDemosWhat’s next

Agenda

Page 3: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

Your app requires connectivity of some kind, but the device is not connected:

• The radio is off• Unknown Wi-Fi network• No Wi-Fi network

Problem

Users are not always connected

Page 4: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

• Desktop• User must move out of app context:• To navigate through Settings to manually toggle radios• To pull out the Charms menu to manually connect to Wi-Fi• To navigate through Settings to start internet sharing

• Phone• User can swipe down from top of screen for quick actions bar (Phone

8.1 only)• Turn Wi-Fi on/off• Turn Bluetooth on/off• Turn internet sharing on/off

• Quick links exist to take users directly to the settings subpage

Prior solutions

How did users get connected before?

Page 5: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

• Radio management APIs• Turn Wi-Fi and BT radios on and off• Windows.Devices.Radios namespace• “radios” deviceCapability

• Wi-Fi scan and connect APIs• Scan for Wi-Fi networks and retrieve their properties• Connect to commonly-used Wi-Fi networks• Foreground applications only• Windows.Devices.WiFi namespace• “wiFiControl” deviceCapability

• Tethering APIs (Mobile hotspot)• Start a hotspot on your device• Windows.Networking.NetworkOperators• Formerly limited only to 2nd party network operators, now public

What’s new in Windows 10

New APIs to make the user experience more seamless

Page 6: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

// Request access to set the radio state, this must be called at least once from the UI threadawait Radio.RequestAccessAsync(); // Turn on WiFi radiosvar radios = await Radio.GetRadiosAsync();foreach (var radio in radios){    if (radio.Kind == RadioKind.WiFi)    {        await radio.SetStateAsync(RadioState.On);    }}

Sample code – Radio management

Page 7: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

Demo – Radio Manager

Page 8: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

//Request access to Wi-Fi radio and enumerate all Wi-Fi radios

var access = await WiFiAdapter.RequestAccessAsync();if (access != WiFiAccessStatus.Allowed){

NotifyUser(“Access denied”);}else{

var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());

if (result.Count >= 1) { firstAdapter = await WiFiAdapter.FromIdAsync(result[0].Id);

} else { NotifyUser(“No WiFi Adapters detected on this machine”); }}

Sample code – Wi-Fi scanning

Page 9: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

//Initiate a Wi-Fi scan and access the scan results

await firstAdapter.ScanAsync();

var report = firstAdapter.NetworkReport;

var message = string.Format(“Network Report Timestamp: {0}”, report.Timestamp);foreach (var network in report.AvailableNetworks){

//Format the network informationmessage += string.Format("\nNetworkName: {0}, BSSID: {1}, RSSI: {2}dBm, Channel Frequency: {3}kHz",

network.Ssid, network.Bssid, network.NetworkRssiInDecibelMilliwatts, network.ChannelCenterFrequencyInKilohertz);

}

Sample code – Wi-Fi scanning

Page 10: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

// Choose one of the available networksvar availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork = availableNetworks[0]; string passPhrase = “password”;

var passwordCredentials = new PasswordCredential(null, null, passPhrase); var connectionResult = await firstAdapter.ConnectAsync(availableNetwork, WiFiConnectionKind.Permanent,

passwordCredentials); if (connectionResult.ConnectionStatus != WiFiConnectionStatus.Success){

// Connection was unsuccessful, indicate error or retry with different input}

Sample code – Wi-Fi connect

Page 11: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

Demo – Wi-Fi Scan and Connect

Page 12: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

NetworkOperatorTetheringManager tetheringManager = null; ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); if (InternetConnectionProfile != null && InternetConnectionProfile.IsWwanConnectionProfile){

tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(InternetConnectionProfile);}

Sample code – Tethering

Page 13: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

try{ NetworkOperatorTetheringOperationResult result = await tetheringManager.StartTetheringAsync(); if (result.Status != TetheringOperationStatus.Success) {

if (result.AdditionalErrorMessage != "") { NotifyUser(result.AdditionalErrorMessage); } else { NotifyUser(GetTetheringErrorString(result.Status)); } }}catch (Exception ex){

NotifyUser("Unexpected exception occurred: " + ex.ToString());}

Sample code – Tethering

Page 14: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

• MSDN documentation and sample apps• Windows.Devices.Radios - http://aka.ms/radiosmsdn• Windows.Devices.WiFi - http://aka.ms/wifimsdn• Windows.Networking.NetworkOperator - http://aka.ms/tetheringmsdn

• Related sessions• Wi-Fi Direct and Wi-Fi Direct Services - http://aka.ms/wfdbuildtalk2015

Call to Action

Page 15: Choose one of the available networks var availableNetworks = firstAdapter.NetworkReport.AvailableNetworks; WiFiAvailableNetwork availableNetwork.

© 2015 Microsoft Corporation. All rights reserved.


Recommended