Write a Program to display the list of sensors supported by the mobile device.

Java:

package com.example.myexperiments;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;

import android.hardware.Sensor;

import android.hardware.SensorManager;

import android.os.Bundle;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    SensorManager smm;

    List<Sensor> sensor;

    ListView lv;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        smm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

        lv = (ListView) findViewById (R.id.lv1);

        sensor = smm.getSensorList(Sensor.TYPE_ALL);

        lv.setAdapter(new ArrayAdapter<Sensor>(this, android.R.layout.simple_list_item_1,  sensor));

    }

}

XML:

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

<LinearLayout 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">

    <ListView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

       android:id="@+id/lv1" />

</LinearLayout>


Comments

Popular posts from this blog

Write a program to create a first display screen on any search engine using auto complete text View

Write a Program to create a toggle button to display the ON/OFF Bluetooth on the display screen.

Write a program to create a login form for social networking website.