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

SensorApp Code

The document provides Java code for an Android application that displays a list of sensors available on the device. It initializes a SensorManager, retrieves the sensor list, and shows the sensor names in a Toast message. The accompanying XML layout defines a simple user interface with a TextView for displaying the sensor list.

Uploaded by

Samruddhi Pawar
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)
10 views3 pages

SensorApp Code

The document provides Java code for an Android application that displays a list of sensors available on the device. It initializes a SensorManager, retrieves the sensor list, and shows the sensor names in a Toast message. The accompanying XML layout defines a simple user interface with a TextView for displaying the sensor list.

Uploaded by

Samruddhi Pawar
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

Android App to Display List of Sensors

Java Code ([Link]):

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

SensorManager sensorManager;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

// Initialize the SensorManager

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

// Get the list of sensors from the device

[Link]<Sensor> sensors = [Link](Sensor.TYPE_ALL);


// Show the sensor names in a simple Toast message

StringBuilder sensorNames = new StringBuilder();

for (Sensor sensor : sensors) {

[Link]([Link]()).append("\n");

// Display all sensor names in a Toast message

[Link](this, [Link](), Toast.LENGTH_LONG).show();

XML Layout (activity_main.xml):

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

<LinearLayout xmlns:android="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<TextView

android:id="@+id/sensorTextView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Sensor List will be shown here"

android:textSize="16sp"/>
</LinearLayout>

You might also like