Ads
Tuesday, March 10, 2020
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:
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>
<?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>
Recommended Articles
- Android
how to remove selected list item in kotlin Apr 02, 2020
how to remove selected list item in kotlin In this Article today learn how to remove the selected items from listview in kotlin. android studio p...
- Android
alert dialog android kotlin exampleApr 01, 2020
alert dialog android kotlin exampleToday learn tutorial alert dialog android kotlin example the following example full source code.Android AlertD...
- Android
android kotlin alert dialog builder exit exampleMar 20, 2020
android kotlin alert dialog builder exit example Today learn android kotlin alert dialog builder exit example. Follow the kotline ...
- Android
how to insert data sqlite using kotlin android Mar 19, 2020
how to insert data SQLite using kotlin android Today learn how to insert data SQLite using kotlin android fol...
Labels:
Android
Subscribe to:
Post Comments (Atom)
WiFi-Manager 2.6.4.536 Crack
ReplyDeleteThis 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.