This website includes Education Information like a programming language, job interview question, general knowledge.mathematics

Education log

PageNavi Results No.

Ads

Tuesday, March 10, 2020

kotlin wifimanager for android studio example

kotlin wifimanager for android studio example


In this article, today learn kotlin wifi manager for android studio example. follow the tutorial kotlin wifi manager for an android studio example.
Android allows applications to access to view access to the state of the wireless connections at a very low level. Application can access almost all the information on a wifi connection.
The information that an application can access includes connected network's link speed, IP address, negotiation state, other network information. Applications can also scan, add, save, terminate and initiate Wi-Fi connections.

follow the kotline wifi manager example:

1.MainActivity.kt :


import android.net.wifi.WifiManager
import android.os.Bundle
import android.app.Activity
import android.content.Context
import android.view.View
import android.view.View.OnClickListener
import android.widget.Button

class MainActivity:Activity() {

  internal var enableButton:Button
  internal var disableButton:Button

   protected fun onCreate(savedInstanceState:Bundle) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    enableButton = findViewById(R.id.button1) as Button
    disableButton = findViewById(R.id.button2) as Button

    enableButton.setOnClickListener(object:OnClickListener() {
      fun onClick(v:View) {
        val wifi = getSystemService(Context.WIFI_SERVICE) as WifiManager
        wifi.setWifiEnabled(true)
      }
    })

    disableButton.setOnClickListener(object:OnClickListener() {
      fun onClick(v:View) {
        val wifi = getSystemService(Context.WIFI_SERVICE) as WifiManager
        wifi.setWifiEnabled(false)
      }
    })

  }
}



2. activity_main.xml:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
           
   <ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageView"
      android:src="@drawable/abc"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true" />
                       
   <Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="76dp"
      android:text="Enable Wifi"
      android:layout_centerVertical="true"
      android:layout_alignEnd="@+id/imageView" />

   <Button
      android:id="@+id/button2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Disable Wifi"
      android:layout_marginBottom="93dp"
      android:layout_alignParentBottom="true"
      android:layout_alignStart="@+id/imageView" />

</RelativeLayout>



3. AndroidManifest.xml:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.wifi.myapplication" >
   <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
   <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  
   <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
     
      <activity
         android:name=".MainActivity"
         android:label="@string/app_name" >
        
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
        
      </activity>
     
   </application>
</manifest>



1 comment:

  1. WiFi-Manager 2.6.4.536 Crack
    This license key aids you in managing all your wireless connections from a single location. The NET framework will be available when you re-distribute the application in Visual C++ after installing it on your computer.

    ReplyDelete