wifi.html 34.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Wi-Fi | Quick Apps</title>
    <meta name="generator" content="VuePress 1.9.5">
    
    <meta name="description" content="Quick App reference guide for developers">
    <meta name="theme-color" content="#38b5ff">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    
    <link rel="preload" href="/developers/assets/css/0.styles.f297bc98.css" as="style"><link rel="preload" href="/developers/assets/js/app.4b1167ed.js" as="script"><link rel="preload" href="/developers/assets/js/2.0c90b5ef.js" as="script"><link rel="preload" href="/developers/assets/js/112.e590539f.js" as="script"><link rel="prefetch" href="/developers/assets/js/10.2156cdfe.js"><link rel="prefetch" href="/developers/assets/js/100.038af2fc.js"><link rel="prefetch" href="/developers/assets/js/101.315bea04.js"><link rel="prefetch" href="/developers/assets/js/102.151e66a2.js"><link rel="prefetch" href="/developers/assets/js/103.9ba01750.js"><link rel="prefetch" href="/developers/assets/js/104.e04d6157.js"><link rel="prefetch" href="/developers/assets/js/105.03af8b7d.js"><link rel="prefetch" href="/developers/assets/js/106.fdbb7328.js"><link rel="prefetch" href="/developers/assets/js/107.0984490c.js"><link rel="prefetch" href="/developers/assets/js/108.2234eb4c.js"><link rel="prefetch" href="/developers/assets/js/109.e15c5ad7.js"><link rel="prefetch" href="/developers/assets/js/11.dc71520b.js"><link rel="prefetch" href="/developers/assets/js/110.7e092174.js"><link rel="prefetch" href="/developers/assets/js/111.1b1d57da.js"><link rel="prefetch" href="/developers/assets/js/113.cf4827c6.js"><link rel="prefetch" href="/developers/assets/js/12.107ffb2e.js"><link rel="prefetch" href="/developers/assets/js/13.5d658c48.js"><link rel="prefetch" href="/developers/assets/js/14.64254d8f.js"><link rel="prefetch" href="/developers/assets/js/15.9a04fe04.js"><link rel="prefetch" href="/developers/assets/js/16.82d55f37.js"><link rel="prefetch" href="/developers/assets/js/17.fdc401b5.js"><link rel="prefetch" href="/developers/assets/js/18.aa734709.js"><link rel="prefetch" href="/developers/assets/js/19.a3bddb91.js"><link rel="prefetch" href="/developers/assets/js/20.898f80cd.js"><link rel="prefetch" href="/developers/assets/js/21.b5f4ba1a.js"><link rel="prefetch" href="/developers/assets/js/22.6999e8ff.js"><link rel="prefetch" href="/developers/assets/js/23.bb7a4ae1.js"><link rel="prefetch" href="/developers/assets/js/24.cf493e39.js"><link rel="prefetch" href="/developers/assets/js/25.eed84f79.js"><link rel="prefetch" href="/developers/assets/js/26.a3822e1c.js"><link rel="prefetch" href="/developers/assets/js/27.c9926129.js"><link rel="prefetch" href="/developers/assets/js/28.910aab3f.js"><link rel="prefetch" href="/developers/assets/js/29.f0f3da68.js"><link rel="prefetch" href="/developers/assets/js/3.98a25a7a.js"><link rel="prefetch" href="/developers/assets/js/30.4dc87f81.js"><link rel="prefetch" href="/developers/assets/js/31.d6c51da3.js"><link rel="prefetch" href="/developers/assets/js/32.9b6a5d46.js"><link rel="prefetch" href="/developers/assets/js/33.f9a34b67.js"><link rel="prefetch" href="/developers/assets/js/34.1be5ed49.js"><link rel="prefetch" href="/developers/assets/js/35.92bad26a.js"><link rel="prefetch" href="/developers/assets/js/36.4269943c.js"><link rel="prefetch" href="/developers/assets/js/37.e67e3e2b.js"><link rel="prefetch" href="/developers/assets/js/38.95710002.js"><link rel="prefetch" href="/developers/assets/js/39.4a27013e.js"><link rel="prefetch" href="/developers/assets/js/4.c45fc624.js"><link rel="prefetch" href="/developers/assets/js/40.f3b3b2c9.js"><link rel="prefetch" href="/developers/assets/js/41.f5a3fb56.js"><link rel="prefetch" href="/developers/assets/js/42.9a1bdcad.js"><link rel="prefetch" href="/developers/assets/js/43.9267a3df.js"><link rel="prefetch" href="/developers/assets/js/44.151a0e89.js"><link rel="prefetch" href="/developers/assets/js/45.6b0cec03.js"><link rel="prefetch" href="/developers/assets/js/46.df37048f.js"><link rel="prefetch" href="/developers/assets/js/47.9fe86222.js"><link rel="prefetch" href="/developers/assets/js/48.77de4866.js"><link rel="prefetch" href="/developers/assets/js/49.1a12d589.js"><link rel="prefetch" href="/developers/assets/js/5.71cdc252.js"><link rel="prefetch" href="/developers/assets/js/50.50213a02.js"><link rel="prefetch" href="/developers/assets/js/51.ac4a08c7.js"><link rel="prefetch" href="/developers/assets/js/52.f54921c8.js"><link rel="prefetch" href="/developers/assets/js/53.8ea79d5f.js"><link rel="prefetch" href="/developers/assets/js/54.194cf5af.js"><link rel="prefetch" href="/developers/assets/js/55.a5b418b9.js"><link rel="prefetch" href="/developers/assets/js/56.ec8192ea.js"><link rel="prefetch" href="/developers/assets/js/57.4b7ea8cb.js"><link rel="prefetch" href="/developers/assets/js/58.6cb47b2e.js"><link rel="prefetch" href="/developers/assets/js/59.44b4341e.js"><link rel="prefetch" href="/developers/assets/js/6.44988a9b.js"><link rel="prefetch" href="/developers/assets/js/60.55f344f0.js"><link rel="prefetch" href="/developers/assets/js/61.0444b094.js"><link rel="prefetch" href="/developers/assets/js/62.856dc838.js"><link rel="prefetch" href="/developers/assets/js/63.09799600.js"><link rel="prefetch" href="/developers/assets/js/64.cc45f664.js"><link rel="prefetch" href="/developers/assets/js/65.9c451be5.js"><link rel="prefetch" href="/developers/assets/js/66.bf2ee7a5.js"><link rel="prefetch" href="/developers/assets/js/67.25ee9554.js"><link rel="prefetch" href="/developers/assets/js/68.44671807.js"><link rel="prefetch" href="/developers/assets/js/69.ba08ab7e.js"><link rel="prefetch" href="/developers/assets/js/7.2f94e492.js"><link rel="prefetch" href="/developers/assets/js/70.30349711.js"><link rel="prefetch" href="/developers/assets/js/71.a36522f9.js"><link rel="prefetch" href="/developers/assets/js/72.8b6101f2.js"><link rel="prefetch" href="/developers/assets/js/73.ba6b048d.js"><link rel="prefetch" href="/developers/assets/js/74.5abf265c.js"><link rel="prefetch" href="/developers/assets/js/75.867935fc.js"><link rel="prefetch" href="/developers/assets/js/76.c444a096.js"><link rel="prefetch" href="/developers/assets/js/77.2c1c557c.js"><link rel="prefetch" href="/developers/assets/js/78.5f7b1c3e.js"><link rel="prefetch" href="/developers/assets/js/79.a680e3f9.js"><link rel="prefetch" href="/developers/assets/js/8.d9a74d5e.js"><link rel="prefetch" href="/developers/assets/js/80.03770288.js"><link rel="prefetch" href="/developers/assets/js/81.cbe2c473.js"><link rel="prefetch" href="/developers/assets/js/82.1c6ac4bf.js"><link rel="prefetch" href="/developers/assets/js/83.d08419a1.js"><link rel="prefetch" href="/developers/assets/js/84.1505c4c2.js"><link rel="prefetch" href="/developers/assets/js/85.b464c282.js"><link rel="prefetch" href="/developers/assets/js/86.e0df47a8.js"><link rel="prefetch" href="/developers/assets/js/87.abcd802c.js"><link rel="prefetch" href="/developers/assets/js/88.07faba71.js"><link rel="prefetch" href="/developers/assets/js/89.9dc9eba0.js"><link rel="prefetch" href="/developers/assets/js/9.21e12ace.js"><link rel="prefetch" href="/developers/assets/js/90.fc31e508.js"><link rel="prefetch" href="/developers/assets/js/91.f5bd9acd.js"><link rel="prefetch" href="/developers/assets/js/92.0572caf1.js"><link rel="prefetch" href="/developers/assets/js/93.544a3b6b.js"><link rel="prefetch" href="/developers/assets/js/94.377a31bf.js"><link rel="prefetch" href="/developers/assets/js/95.27737fb7.js"><link rel="prefetch" href="/developers/assets/js/96.9655a8bb.js"><link rel="prefetch" href="/developers/assets/js/97.345971d4.js"><link rel="prefetch" href="/developers/assets/js/98.6dabc14b.js"><link rel="prefetch" href="/developers/assets/js/99.6d4060bc.js">
    <link rel="stylesheet" href="/developers/assets/css/0.styles.f297bc98.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/developers/" class="home-link router-link-active"><!----> <span class="site-name">Quick Apps</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/developers/guide/" class="nav-link">
  Guide
</a></div><div class="nav-item"><a href="/developers/components/" class="nav-link">
  UI Components
</a></div><div class="nav-item"><a href="/developers/services/" class="nav-link router-link-active">
  API &amp; Services
</a></div><div class="nav-item"><a href="https://quick-app-initiative.ow2.io" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Quick App Initiative
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/developers/guide/" class="nav-link">
  Guide
</a></div><div class="nav-item"><a href="/developers/components/" class="nav-link">
  UI Components
</a></div><div class="nav-item"><a href="/developers/services/" class="nav-link router-link-active">
  API &amp; Services
</a></div><div class="nav-item"><a href="https://quick-app-initiative.ow2.io" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Quick App Initiative
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Guide</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>UI Components</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>API &amp; Services</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/developers/services/" aria-current="page" class="sidebar-link">Summary of APIs</a></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><p class="sidebar-heading"><span>Basic Services</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><p class="sidebar-heading"><span>UI Interaction</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><p class="sidebar-heading"><span>Network</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><p class="sidebar-heading"><span>Files and Data Management</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><p class="sidebar-heading open"><span>System Services</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/developers/services/alarms.html" class="sidebar-link">Alarms</a></li><li><a href="/developers/services/app-configuration.html" class="sidebar-link">App Configuration</a></li><li><a href="/developers/services/audio-volume.html" class="sidebar-link">Audio Volume</a></li><li><a href="/developers/services/battery-level.html" class="sidebar-link">Battery Level</a></li><li><a href="/developers/services/bluetooth.html" class="sidebar-link">Bluetooth</a></li><li><a href="/developers/services/calendar.html" class="sidebar-link">Calendar Events</a></li><li><a href="/developers/services/clipboard.html" class="sidebar-link">Clipboard</a></li><li><a href="/developers/services/contacts.html" class="sidebar-link">Contacts</a></li><li><a href="/developers/services/device.html" class="sidebar-link">Device Information</a></li><li><a href="/developers/services/home-screen-icon.html" class="sidebar-link">Home Screen Icon</a></li><li><a href="/developers/services/location.html" class="sidebar-link">Location</a></li><li><a href="/developers/services/mediaquery.html" class="sidebar-link">Media Queries</a></li><li><a href="/developers/services/screen-brightness.html" class="sidebar-link">Screen Brightness</a></li><li><a href="/developers/services/sensor.html" class="sidebar-link">Sensors</a></li><li><a href="/developers/services/sms.html" class="sidebar-link">SMS Messages</a></li><li><a href="/developers/services/wifi.html" aria-current="page" class="active sidebar-link">Wi-Fi</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/developers/services/wifi.html#manifest-declaration" class="sidebar-link">Manifest Declaration</a></li><li class="sidebar-sub-header"><a href="/developers/services/wifi.html#module-import" class="sidebar-link">Module Import</a></li><li class="sidebar-sub-header"><a href="/developers/services/wifi.html#methods" class="sidebar-link">Methods</a></li><li class="sidebar-sub-header"><a href="/developers/services/wifi.html#events" class="sidebar-link">Events</a></li></ul></li></ul></section></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><p class="sidebar-heading"><span>Multimedia</span> <span class="arrow right"></span></p> <!----></section></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="wi-fi"><a href="#wi-fi" class="header-anchor">#</a> Wi-Fi</h1> <p><strong>WiFi connection management.</strong></p> <p>Methods for searching nearby Wi-Fi signals and attach to hotspots.</p> <div class="custom-block warning"><p class="custom-block-title">WARNING</p> <p>If the device's location capabilities are disabled, these methods don't work.</p></div> <h2 id="manifest-declaration"><a href="#manifest-declaration" class="header-anchor">#</a> Manifest Declaration</h2> <p>You need to declare the use of this API in the <a href="/developers/guide/manifest.html#features">manifest's <code>features</code></a> member:</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span><span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;system.wifi&quot;</span><span class="token punctuation">}</span>
</code></pre></div><h2 id="module-import"><a href="#module-import" class="header-anchor">#</a> Module Import</h2> <p>Before using this service in a component, you need to <a href="/developers/guide/scripting.html#import-and-export-modules">import the module</a> in the script section of the <a href="../guide/ux-documents">UX document</a>.</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">import</span> wifi <span class="token keyword">from</span> <span class="token string">'@system.wifi'</span> 
</code></pre></div><p>Or</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">let</span> wifi <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">&quot;@system.wifi&quot;</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="methods"><a href="#methods" class="header-anchor">#</a> Methods</h2> <p>This service has the following methods:</p> <ul><li><a href="#connect-ssid-bssid-password-success-fail-complete"><code>connect({SSID,BSSID,password,success,fail,complete})</code></a></li> <li><a href="#scan-success-fail-complete"><code>scan({success,fail,complete})</code></a></li> <li><a href="#getconnectedwifi-success-fail-complete"><code>getConnectedWifi({success,fail,complete})</code></a></li></ul> <h3 id="connect-ssid-bssid-password-success-fail-complete"><a href="#connect-ssid-bssid-password-success-fail-complete" class="header-anchor">#</a> <code>connect({SSID,BSSID,password,success,fail,complete})</code></h3> <p><strong>Connects to a Wi-Fi hotspot</strong>.</p> <p>If you already know information about a specific Wi-Fi hotspot, you can call this method directly.</p> <div class="custom-block warning"><p class="custom-block-title">WARNING</p> <p>The connection will only be established after the user is notified by the operating system and agrees to connect.</p></div> <h4 id="arguments"><a href="#arguments" class="header-anchor">#</a> Arguments</h4> <p>This method requires an <code>object</code> with the following attributes:</p> <ul><li><code>SSID</code> (<code>string</code>). Mandatory attribute that indicates the SSID of the network.</li> <li><code>BSSID</code> (<code>string</code>). Mandatory attribute that indicates the BSSID of the network.</li> <li><code>password</code> (<code>string</code>). Mandatory attribute that indicates the password.</li> <li><code>success</code>	(<code>function</code>). Optional callback function corresponding to the successful execution.</li> <li><code>fail</code> (<code>function</code>). Optional callback function corresponding to a failed execution.</li> <li><code>complete</code> (<code>function</code>). Optional callback function corresponding to the end of the execution.</li></ul> <p>Example:</p> <div class="language-js extra-class"><pre class="language-js"><code>wifi<span class="token punctuation">.</span><span class="token function">connect</span><span class="token punctuation">(</span><span class="token punctuation">{</span> 
    <span class="token constant">SSID</span><span class="token operator">:</span><span class="token string">'myssid'</span><span class="token punctuation">,</span> 
    <span class="token constant">BSSID</span><span class="token operator">:</span><span class="token string">'mybssid'</span><span class="token punctuation">,</span> 
    password<span class="token operator">:</span><span class="token string">''</span><span class="token punctuation">,</span> 
    <span class="token function-variable function">success</span><span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'connect wifi success'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token punctuation">}</span><span class="token punctuation">,</span> 
    <span class="token function-variable function">fail</span><span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">errmsg<span class="token punctuation">,</span> errorCode</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'connect failed '</span> <span class="token operator">+</span> errmsg<span class="token operator">+</span><span class="token string">', error = '</span><span class="token operator">+</span>errorCode<span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token punctuation">}</span> 
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="scan-success-fail-complete"><a href="#scan-success-fail-complete" class="header-anchor">#</a> <code>scan({success,fail,complete})</code></h3> <p><strong>Method to get the list of Wi-Fi networks around.</strong></p> <p>Use the <a href="#onscanned-wifilist"><code>onscanned</code></a> listener to get the list of the networks once they are discovered.</p> <h4 id="arguments-2"><a href="#arguments-2" class="header-anchor">#</a> Arguments</h4> <p>This method requires an <code>object</code> with the following attributes:</p> <ul><li><code>success</code>	(<code>function(res)</code>). Optional callback function corresponding to the successful execution.</li> <li><code>fail</code> (<code>function</code>). Optional callback function corresponding to a failed execution.</li> <li><code>complete</code> (<code>function</code>). Optional callback function corresponding to the end of the execution.</li></ul> <p>Example:</p> <div class="language-js extra-class"><pre class="language-js"><code>wifi<span class="token punctuation">.</span><span class="token function">scan</span><span class="token punctuation">(</span><span class="token punctuation">{</span> 
    <span class="token function-variable function">success</span><span class="token operator">:</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'scan wifi success'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     
    <span class="token punctuation">}</span><span class="token punctuation">,</span> 
    <span class="token function-variable function">fail</span><span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">errmsg<span class="token punctuation">,</span> errorCode</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'scan failed '</span> <span class="token operator">+</span> errmsg<span class="token operator">+</span><span class="token string">', error = '</span><span class="token operator">+</span>errorCode<span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token punctuation">}</span> 
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="getconnectedwifi-success-fail-complete"><a href="#getconnectedwifi-success-fail-complete" class="header-anchor">#</a> <code>getConnectedWifi({success,fail,complete})</code></h3> <p><strong>Method to get information about the Wi-Fi network currently connected.</strong></p> <h4 id="arguments-3"><a href="#arguments-3" class="header-anchor">#</a> Arguments</h4> <p>This method requires an <code>object</code> with the following attributes:</p> <ul><li><code>success</code>	(<code>function(res)</code>). Optional callback function corresponding to the successful execution. The function has an <code>object</code> argument with the following attributes:
<ul><li><code>SSID</code> (<code>string</code>). The SSID of the network.</li> <li><code>BSSID</code> (<code>string</code>). The BSSID of the network.</li> <li><code>secure</code> (<code>boolean</code>). Flag that indicates if the network hotspot is secured (<code>true</code>) or not.</li> <li><code>signalStrength</code> (<code>number</code>). Quality of the Wi-Fi signal. The value is an <code>integer</code> between <code>–100</code> and <code>0</code>, indicating the dBm of the signal.</li></ul></li> <li><code>fail</code> (<code>function(msg,code)</code>). Optional callback function corresponding to a failed execution. The possible codes are:
<ul><li><code>1000</code> (<code>password error</code>): Incorrect Wi-Fi password.</li> <li><code>1001</code> (<code>connection timeout</code>): Connection timed out.</li> <li><code>1002</code> (<code>duplicate request</code>): The device has already connected to the Wi-Fi hotspot.</li> <li><code>1003</code> (<code>wifi not turned on</code>): Wi-Fi connection is disabled.</li> <li><code>1004</code> (<code>gps not turned on</code>): GPS positioning is disabled.</li> <li><code>1005</code> (<code>invalid SSID</code>): Invalid Wi-Fi device SSID.</li> <li><code>500</code> (<code>quick app in background</code>): The app cannot be operated in the background.</li></ul></li> <li><code>complete</code> (<code>function</code>). Optional callback function corresponding to the end of the execution.</li></ul> <div class="custom-block tip"><p class="custom-block-title">Values of reference (dBm)</p> <ul><li><code>–49</code> to <code>0</code>: Signal is strong.</li> <li><code>–70</code> to <code>–50</code>: Signal is weak.</li> <li>&lt;<code>–70</code>: It is difficult to establish a connection or keep connected.</li></ul></div> <p>Example:</p> <div class="language-js extra-class"><pre class="language-js"><code>wifi<span class="token punctuation">.</span><span class="token function">getConnectedWifi</span><span class="token punctuation">(</span><span class="token punctuation">{</span> 
    <span class="token function-variable function">success</span><span class="token operator">:</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">ret</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'ssid = '</span><span class="token operator">+</span>ret<span class="token punctuation">.</span><span class="token constant">SSID</span><span class="token operator">+</span><span class="token string">', BSSID = '</span><span class="token operator">+</span> ret<span class="token punctuation">.</span><span class="token constant">BSSID</span><span class="token operator">+</span><span class="token string">', secure = '</span><span class="token operator">+</span>ret<span class="token punctuation">.</span>secure<span class="token operator">+</span><span class="token string">', signalStrength = '</span><span class="token operator">+</span>ret<span class="token punctuation">.</span>signalStrength<span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token punctuation">}</span><span class="token punctuation">,</span> 
    <span class="token function-variable function">fail</span><span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">errmsg<span class="token punctuation">,</span> errorCode</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'getConnectedWifi failed '</span><span class="token punctuation">)</span> 
    <span class="token punctuation">}</span> 
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="events"><a href="#events" class="header-anchor">#</a> Events</h2> <p>This service implements the following event listeners:</p> <ul><li><a href="#onscanned-wifilist"><code>onscanned({wifiList})</code></a></li> <li><a href="#onstatechanged-ssid-bssid-secure-signalstrength-state"><code>onstatechanged({SSID,BSSID,secure,signalStrength,state})</code></a></li></ul> <h3 id="onscanned-wifilist"><a href="#onscanned-wifilist" class="header-anchor">#</a> <code>onscanned({wifiList})</code></h3> <p><strong>Method to be triggered with the scanning process finds a network</strong>.</p> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>To cancel the listener, use <code>wifi.onscanned = null</code>.</p></div> <h4 id="arguments-4"><a href="#arguments-4" class="header-anchor">#</a> Arguments</h4> <p>This method requires a callback <code>function</code> with an <code>object</code> as argument that has the following member:</p> <ul><li><code>wifiList</code> (<code>array</code>). List of <code>objects</code> with information about the networks found. Every entry has the following members:
<ul><li><code>SSID</code> (<code>string</code>). The SSID of the network.</li> <li><code>BSSID</code> (<code>string</code>). The BSSID of the network.</li> <li><code>secure</code> (<code>boolean</code>). Flag that indicates if the network hotspot is secured (<code>true</code>) or not.</li> <li><code>signalStrength</code> (<code>number</code>). Quality of the Wi-Fi signal. The value is an <code>integer</code> between <code>–100</code> and <code>0</code>, indicating the dBm of the signal.</li></ul></li></ul> <p>Example:</p> <div class="language-js extra-class"><pre class="language-js"><code>wifi<span class="token punctuation">.</span><span class="token function-variable function">onscanned</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">data</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'scanned result data = '</span><span class="token operator">+</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     
<span class="token punctuation">}</span>
</code></pre></div><h3 id="onstatechanged-ssid-bssid-secure-signalstrength-state"><a href="#onstatechanged-ssid-bssid-secure-signalstrength-state" class="header-anchor">#</a> <code>onstatechanged({SSID,BSSID,secure,signalStrength,state})</code></h3> <p><strong>Method to be triggered with the state of the network connection changes</strong>.</p> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>To cancel the listener, use <code>wifi.onstatechanged = null</code>.</p></div> <h4 id="arguments-5"><a href="#arguments-5" class="header-anchor">#</a> Arguments</h4> <p>This method requires a callback <code>function</code> with an <code>object</code> as argument that has the following member:</p> <ul><li><code>wifiList</code> (<code>array</code>). List of <code>objects</code> with information about the networks found. Every entry has the following members:
<ul><li><code>SSID</code> (<code>string</code>). The SSID of the network.</li> <li><code>BSSID</code> (<code>string</code>). The BSSID of the network.</li> <li><code>secure</code> (<code>boolean</code>). Flag that indicates if the network hotspot is secured (<code>true</code>) or not.</li> <li><code>state</code> (<code>number</code>). Indicator of the status of the connection (<code>1</code>: connected, <code>0</code>: disconnected).</li></ul></li></ul> <p>Example:</p> <div class="language-js extra-class"><pre class="language-js"><code>wifi<span class="token punctuation">.</span><span class="token function-variable function">onstatechanged</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">data</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>data<span class="token punctuation">.</span>state<span class="token operator">+</span><span class="token string">' ssid = '</span><span class="token operator">+</span>data<span class="token punctuation">.</span><span class="token constant">SSID</span><span class="token operator">+</span><span class="token string">', bssid = '</span><span class="token operator">+</span>data<span class="token punctuation">.</span><span class="token constant">BSSID</span><span class="token operator">+</span><span class="token string">', secure = '</span><span class="token operator">+</span>data<span class="token punctuation">.</span>secure<span class="token operator">+</span><span class="token string">' signalStrength = '</span><span class="token operator">+</span>data<span class="token punctuation">.</span>signalStrength<span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
</code></pre></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://gitlab.ow2.org/quick-app-initiative/quick-app-initiative/edit/master/technology-guides/developer-docs/content/services/wifi.md" target="_blank" rel="noopener noreferrer">Help us improve this document!</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">Last Updated:</span> <span class="time">11/22/2021, 3:47:13 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">

      <a href="/developers/services/sms.html" class="prev">
        SMS Messages
      </a></span> <span class="next"><a href="/developers/services/animations.html">
        Animations
      </a>

    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/developers/assets/js/app.4b1167ed.js" defer></script><script src="/developers/assets/js/2.0c90b5ef.js" defer></script><script src="/developers/assets/js/112.e590539f.js" defer></script>
  </body>
</html>