Created
November 24, 2018 00:04
-
-
Save madhankumardroid/01510dbd526dccb294cb1df83b9f6ac3 to your computer and use it in GitHub Desktop.
Get the list of sensors in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
ListView listView ; | |
SensorManager sensorManager ; | |
List<Sensor> listsensor; | |
List<String> liststring ; | |
ArrayAdapter<String> adapter ; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
listView = (ListView)findViewById(R.id.listview1); | |
liststring = new ArrayList<String>(); | |
sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); | |
listsensor = sensorManager.getSensorList(Sensor.TYPE_ALL); | |
for(int i=0; i<listsensor.size(); i++){ | |
liststring.add(listsensor.get(i).getName()); | |
} | |
adapter = new ArrayAdapter<String>(MainActivity.this, | |
android.R.layout.simple_list_item_2, | |
android.R.id.text1, liststring | |
); | |
listView.setAdapter(adapter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment