0

I'm developing a pure java SDK based on JDK 8, and its jar will integrate to Android App or Windows program, but for some reasons, I want to get which manufacturer or brand the SDK running on, is there have JDK API support to get that?

sunjinbo
  • 2,137
  • 4
  • 22
  • 45
  • I just only want to use Java API, not Android API. – sunjinbo May 06 '23 at 06:24
  • You should clarify how you are communicating with the Android device and where is the JDK running either on a PC or on a Android device. – Morrison Chang May 06 '23 at 07:10
  • If you don't want to use reflection to access Android API if present you can sill try to get some details using `System.getProperty("http.agent")`. It returns something like `Dalvik/2.1.0 (Linux; U; Android 12; Pixel 3a Build/SP2A.220505.008)`. – Robert May 06 '23 at 13:32

1 Answers1

1

is there have JDK API support to get that?

Well, in a word, no... You're trying to communicate with an Android device. When talk about pure Java SDK. It has certain methods to communicate with the OS with the help of JVM. But even Android is a Linux kernel based OS, you can't do it directly. IT's because pure Java SDK doesn't come with tools to contact an Android VM. To do that you need Android SDK.

Of course you can get some information in the way of @Robert But it'll not be recommended by Google. It'll create unsecure situations (Not the given example by @Robert). Perhaps your app may be flagged as insecure and maybe removed, if you tried to use pure SDK somehow. So it's not recommended at all.

If your problem is that you want to create a jar library that can communicate with both PC and Android, they there's a proper way of doing it. You can use Kotlin Multiplatform Library (Can be created using IntelliJ Idea). Or you just can create KVVM project in Android Studio. Or you may check whether the device is an Android or a PC in the jar library code, and they do separate actions. You can use Android SDK codes if the device is an Android and can use pure Java SDK if it's a PC.

(I'm just guessing what you need) And what did you mean by,

I'm developing a pure java SDK

For android if you use Android SDK you can use these methods

System.getProperty("os.version") //To get OS and Version
android.os.Build.VERSION.INCREMENTAL //To get OS Version
android.os.Build.VERSION.SDK_INT // To Get API Level
android.os.Build.DEVICE //To get Device
android.os.Build.MODEL //To get Device Model
android.os.Build.PRODUCT //To get Device Product.

But I highly recommend if you're developing a library or something for both platforms. Kotlin Multiplatform Library (No need to use Kotlin, you can use Java) have android, native, jvm and common source directories, so you can share common codes with your jvm library and android library.

I reccomend you researching more for library (in your words SDK) development.