0% found this document useful (0 votes)
8 views3 pages

Practical No 20

The document contains an Android application layout and main activity code for managing a Wi-Fi service. It includes a simple user interface with two buttons to start and stop the Wi-Fi service. The MainActivity class handles the button click events to start and stop the service using intents.

Uploaded by

Vaman Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Practical No 20

The document contains an Android application layout and main activity code for managing a Wi-Fi service. It includes a simple user interface with two buttons to start and stop the Wi-Fi service. The MainActivity class handles the button click events to start and stop the service using intents.

Uploaded by

Vaman Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exp.

20

#activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

android:padding="16dp">

<Button

android:id="@+id/startWifiButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Start Wi-Fi Service" />

<Button

android:id="@+id/stopWifiButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Stop Wi-Fi Service"

android:layout_marginTop="20dp" />

</LinearLayout>
#MainActivity.java

package com.example.wifiservice;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private Button startWifiButton, stopWifiButton;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

startWifiButton = findViewById(R.id.startWifiButton);

stopWifiButton = findViewById(R.id.stopWifiButton);

// Start the service to enable Wi-Fi

startWifiButton.setOnClickListener(v -> {

Intent startServiceIntent = new Intent(MainActivity.this, WifiService.class);

startService(startServiceIntent); // Start the service


});

// Stop the service and disable Wi-Fi

stopWifiButton.setOnClickListener(v -> {

Intent stopServiceIntent = new Intent(MainActivity.this, WifiService.class);

stopService(stopServiceIntent); // Stop the service

});

You might also like