这是indexloc提供的服务,不要输入任何密码
Skip to content

Added(SensorAPI): Add option to show full sensor info #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/src/main/java/com/termux/api/apis/SensorAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ private void postSensorCommandResult(final Context context, final Intent intent,
});
}

private static JSONObject getSensorInfo(Sensor sensor) throws JSONException {
JSONObject obj = new JSONObject();
obj.put("name", sensor.getName());
obj.put("max_range", sensor.getMaximumRange());
obj.put("min_delay", sensor.getMinDelay());
obj.put("power", sensor.getPower());
obj.put("resolution", sensor.getResolution());
obj.put("type", sensor.getStringType());
obj.put("vendor", sensor.getVendor());
obj.put("version", sensor.getVersion());
return obj;
}

/*
* -----
Expand All @@ -196,10 +208,16 @@ private void postSensorCommandResult(final Context context, final Intent intent,
JSONArray sensorArray = new JSONArray();
List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);

boolean showInfo = intent.getBooleanExtra("info", false);

try {
for (int j = 0; j < sensorList.size(); ++j) {
Sensor sensor = sensorList.get(j);
sensorArray.put(sensor.getName());
if (showInfo) {
sensorArray.put(getSensorInfo(sensor));
} else {
sensorArray.put(sensor.getName());
}
}
JSONObject output = new JSONObject();
output.put("sensors", sensorArray);
Expand Down