I am trying to use
SystemProperties.get();
but not able to import the android.os.SystemProperties
package bit of googling tells me its hidden, is there any way around this ?
I am trying to use
SystemProperties.get();
but not able to import the android.os.SystemProperties
package bit of googling tells me its hidden, is there any way around this ?
SystemProperties
is a hidden class that is only available to platform-level code. You could try to access it via reflection, but this is not recommended.
It is easy to confuse Android's SystemProperties
class with the old-style Java way of doing properties, namely java.lang.System.getProperty()
. Note that these are two totally separate systems. An important difference is that the Java mechanism works only within a given process, whereas the Android SystemProperties
works across processes.
As an app developer, although you don't normally get a Java-based API into Android's Android SystemProperties
, you can inspect the SystemProperties
at the command-line using
adb shell getprop
You can import import android.os.Bundle; and then you can access System properties using System.getProperty("os.name");
you can access any property by using System.getProperty('Property name');
add 'layoutlib.jar" to your project's Java Build Path, and then, you can use "import android.os.SystemProperties;"
if want to get device property, for OS information you may check http://developer.android.com/reference/android/os/Build.html
just need to import android.os.Build;
One thing you can try is, comment the
LOCAL_SDK_VERSION := current
in Android.mk. Using this way you can able to call hidden apis from the app
One hacky way is to create your own SystemProperties
class on your classpath so that your code compiles and works and then exclude it from your build. If class then exists on android device, it works fine. I do this quite often for very specific situations, but I wouldn't recommend this on commercial application for various versions and devices.
You can base it on source code class and just leave api that you need.
Example class:
package android.os;
public class SystemProperties {
public static String get(String key) {
return "";
}
}
Then you just need exclude that class from your android/sourcesets/main in gradle file, for example:
sourceSets {
main {
java {
exclude 'android/**/*.java'
}
}
}