0% found this document useful (0 votes)
2 views

practical no 22

The document outlines a practical programming task to display a list of sensors supported by mobile devices using Android. It includes an XML layout file for the user interface and a Java class that retrieves and displays sensor information. The program initializes a TextView to show the sensor names, vendors, and versions, updating the visibility as sensors are listed.

Uploaded by

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

practical no 22

The document outlines a practical programming task to display a list of sensors supported by mobile devices using Android. It includes an XML layout file for the user interface and a Java class that retrieves and displays sensor information. The program initializes a TextView to show the sensor names, vendors, and versions, updating the visibility as sensors are listed.

Uploaded by

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

Practical No : 22

1) Write a program to display the list of sensors supported by the mobile devices.
Activity_Main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/tv"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.practicalno22;

import androidx.appcompat.app.AppCompatActivity;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.util.List;

public class MainActivity extends AppCompatActivity {


TextView tv1 = null;
private SensorManager mSensorManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv1 = (TextView) findViewById(R.id.tv);


tv1.setVisibility(View.GONE);
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
List<Sensor> mList = mSensorManager.getSensorList(Sensor.TYPE_ALL);

for (int i = 0; i < mList.size(); i++) {


tv1.setVisibility(View.VISIBLE);
tv1.append("\n" + mList.get(i).getName() + "\n" + mList.get(i).getVendor() + "\n" +
mList.get(i).getVersion());
}
}
}

Output:

You might also like