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

All Available Sensors Supported by Device

The document contains a Java code for an Android application that displays a list of all available sensors on the device. It initializes a SensorManager, retrieves the sensor list, and populates two TextViews with the sensor names and their corresponding indices. The application is structured within the MainActivity class, extending AppCompatActivity.
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)
0 views

All Available Sensors Supported by Device

The document contains a Java code for an Android application that displays a list of all available sensors on the device. It initializes a SensorManager, retrieves the sensor list, and populates two TextViews with the sensor names and their corresponding indices. The application is structured within the MainActivity class, extending AppCompatActivity.
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/ 1

package com.example.

sensorlist;

import androidx.appcompat.app.AppCompatActivity;

import android.hardware.Sensor;

import android.hardware.SensorManager;

import android.os.Bundle;

import android.widget.TextView;

import java.util.List;

public class MainActivity extends AppCompatActivity {

TextView tv1,tv0;

SensorManager sm;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

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

tv0=(TextView)findViewById(R.id.tv0);

sm = (SensorManager) getSystemService(SENSOR_SERVICE);

List<Sensor> sensorList = sm.getSensorList(Sensor.TYPE_ALL);

StringBuilder sb=new StringBuilder();

StringBuilder sb1=new StringBuilder();

int i=1;

for(Sensor s:sensorList){

sb1.append(Integer.toString(i)+"\n");

sb.append(s.getName()+"\n");

i=i+1;

tv0.setText(sb1);

tv1.setText(sb);

You might also like