How to scan the wifi in ionic 3?(android)

Hi, I am going to teach about how to scan the surrounding wifi in ionic 3 and angular 4?(android and ios)

First we want install the cordova and ionic Native Plugin.
              $ ionic cordova plugin add cordova-pulgin-hotspot
              $ npm install --save @ionic-native/hotspot

app.module.ts
            Now we want to import following lines in app.module.ts
            import { Hotspot, HotspotNetwork } from '@ionic-native/hotspot';
             ......
             ......
            providers: [
       ....
       ....
          Hotspot,
         ]
Home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Hotspot, HotspotNetwork } from '@ionic-native/hotspot';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'})
export class HomePage {
  data: any;
  constructor(public navCtrl: NavController,private hotspot: Hotspot) {

  }

  ionViewDidLoad(){
    this.hotspot.scanWifi().then((networks: Array<HotspotNetwork>) => {
      this.data=networks;
      console.log(".........hotspot..........",JSON.stringify(networks));
    });

  }
}

Home.html

       <ion-header>
           <ion-navbar>
              <ion-title>
                 Wifi Scanner
             </ion-title>
         </ion-navbar>
      </ion-header>

    <ion-content>
     <ion-list>
        <ion-item *ngFor="let x of data">
            <ion-avatar item-start>
            <img src="assets/img/images.png">
            </ion-avatar >
             <p>{{x.SSID}}</p>
          </ion-item>
      </ion-list>
   </ion-content>









How to scan the wifi in ionic 3?(android) How to scan the wifi in ionic 3?(android) Reviewed by Sudhan on October 03, 2017 Rating: 5

6 comments:

  1. Hi, i've this error:
    cordova plugin add cordova-pulgin-hotspot --save
    Error: Registry returned 404 for GET on https://registry.npmjs.org/cordova-pulgin-hotspot

    [ERROR] An error occurred while running cordova plugin add cordova-pulgin-hotspot --save (exit code 1).

    Do you have a Ionic 3 working sample project ?

    ReplyDelete
    Replies
    1. i am also working in ionic 3
      once again remove the plugin and add the plugin once again

      Delete
  2. Does it work with ios as well?

    ReplyDelete
  3. It fabricates similarity and connection among youngsters In any case these diversions are somewhat costly. neko atsume tips

    ReplyDelete
  4. i know this link is super old, but i'm getting this error:

    TypeError: Object(...) is not a function
    at Hotspot.scanWifi (http://localhost:8100/build/vendor.js:81012:122)
    at HomePage.webpackJsonp.248.HomePage.ionViewWillEnter (http://localhost:8100/build/main.js:61:22)
    at ViewController._lifecycle (http://localhost:8100/build/vendor.js:22620:33)
    at ViewController._willEnter (http://localhost:8100/build/vendor.js:22518:14)
    at NavControllerBase._willEnter (http://localhost:8100/build/vendor.js:53453:18)
    at http://localhost:8100/build/vendor.js:53346:39
    at t.invoke (http://localhost:8100/build/polyfills.js:3:14976)
    at Object.onInvoke (http://localhost:8100/build/vendor.js:5396:33)
    at t.invoke (http://localhost:8100/build/polyfills.js:3:14916)
    at r.run (http://localhost:8100/build/polyfills.js:3:10143)


    The ionic slack is completely useless

    ReplyDelete
  5. One observation, I think that this plugin not work in V4, I back version to V3, I tested and now work in V3

    ReplyDelete

LightBlog
Powered by Blogger.