6

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 ?

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Sunny Kumar Aditya
  • 2,806
  • 4
  • 26
  • 38
  • 2
    try reading this question: [http://stackoverflow.com/questions/2641111/where-is-android-os-systemproperties](http://stackoverflow.com/questions/2641111/where-is-android-os-systemproperties) – thepoosh May 02 '12 at 07:53
  • How about the solution here: https://stackoverflow.com/questions/13564281/android-os-servicemanager-not-found-while-building – MMJ Jun 18 '19 at 12:57

6 Answers6

11

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
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
Jo Jo
  • 7,245
  • 5
  • 34
  • 49
2

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');

Anil Jadhav
  • 2,128
  • 1
  • 17
  • 31
0

add 'layoutlib.jar" to your project's Java Build Path, and then, you can use "import android.os.SystemProperties;"

moasm
  • 11
  • 1
0

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;

and0421
  • 181
  • 1
  • 3
0

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

MMJ
  • 519
  • 1
  • 9
  • 26
-1

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'
        }
    }
}
K.H.
  • 1,383
  • 13
  • 33