Is there a Java SE sensor API? [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this questionDoes anyone know of a "standardized" Java API for working with sensors, and which is closely tied to Java ME as is the case with JSR 256?
I'm writing a Java library for interfacing with a sensor network consisting of several different types of sensors (mostly simple stuff such as temperature, humidity, GPS, etc.).
So far I've rolled my own interface, and users have to write apps against thi开发者_开发技巧s. I would like to change this approach and implement a "standard" API so that implementations aren't that closely tied to my library.
I've looked at JSR 256, but that really isn't a great solution as it's for Java ME, and my library is mostly used by Android devices or laptops running the full Java SE.
JSR-256 does not seem to be limited or restricted in the types of sensors it supports. Appendix E contains sensor definitions, but those are just the recommended data a certain type of sensor should handle. There does not seem to be anything stopping somebody from defining additional sensor types.
I would suggest you implement to JSR-256 and then just include its packages:
- javax.microedition.sensor
- javax.microedition.sensor.control
...in your distribution. Since they're targeting limited devices, the library is bound to be very compact. As long as you would not be prohibited from re-distributing the reference implementation of JSR-256 it would make sense to plan to do so.
Not quite. JSR-275 was intended to have part of its functionality (Quantities and a Unit type very similar to that in 256) but the SE/EE EC turned it down.
Consolidation between SE and ME as mentioned by Oracle may lead to a more common Sensor API and Unit framework some time, but it's unlikely before Java 8.
Werner
In android there is the android.hardware
package that contains a class Sensor
, all in all quite similar to tje JSR 256 sensor api. Please see what you can do using that. Maybe it's even a reasonable approach to implement that in Java SE, for as far as I know, there is no Java SE sensor api.
Indeed, Oracle now spread the news, some form of SE Sensor API was desired for Java 8.
It was added to OpenJDK after Java 8: http://openjdk.java.net/projects/dio/ Works both with Java ME and SE (Embedded).
精彩评论