ulfben icon

Listing all sensors (Android)

ulfben | PRO | 03/07/17 04:42:12 PM UTC | 0 ⭐ | 1275 👁️ | Never ⏰ | []
Java |

900 B

|

None

|

0 👍

/

0 👎

private SensorManager mSensorManager;
 
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    // Get the texts fields of the layout and set to invisible
    TextView sensorCountText = 
        (TextView) findViewById(R.id.sensorCountText);
    TextView sensorNamesText = 
        (TextView) findViewById(R.id.sensorNamesText);
    
    // Get the SensorManager
    mSensorManager = 
        (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    
    // get a list of available sensors
    List<Sensor> sensors = 
        mSensorManager.getSensorList(Sensor.TYPE_ALL);
        
    // Print how may Sensors there are
    sensorCountText.setText(sensors.size() +" sensors available.");
    
    // Print the name of each Sensor
    StringBuilder out = new StringBuilder();
    for(Sensor s : sensors){        
        out.append(s.getName()).append("\n");
    }
    sensorNamesText.setText(out.toString());
}

Comments

  • Gyqizv icon
    04/02/26 05:59:24 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎