How to import android.os.SystemProperties

I'm trying to use

SystemProperties.get();

but unable to import the android.os.SystemPropertiesgoogling package bit , tells me its hidden, is there any way around this?

+4
source share
6 answers

SystemPropertiesis a hidden class that is only available for platform level code. You can try to access it through reflection, but this is not recommended.

The Android class is SystemPropertieseasily confused with the old Java style to create properties, namely with java.lang.System.getProperty(). Please note that these are two completely different systems. An important difference is that the Java mechanism only works inside this process, while Android SystemPropertiesworks between processes.

, API Java Android Android SystemProperties, SystemProperties ,

adb shell getprop
+8

import android.os.Bundle;, , System.getProperty( "os.name" );

System.getProperty('Property name');

+2

"layoutlib.jar" Java Build Path, "import android.os.SystemProperties;"

0

- SystemProperties , , . Android, . , .

You can base it on the source code class and just leave the api you need.

Class Example:

package android.os;

public class SystemProperties {

    public static String get(String key) {
        return "";
    }

}

Then you just need to exclude this class from your android / sourcesets / main in the Gradle file, for example:

sourceSets {
    main {
        java {
            exclude 'android/**/*.java'
        }
    }
}
0
source

One thing you can try is to comment

LOCAL_SDK_VERSION: = current

in Android.mk. Using this method, you can call the hidden apis from the application.

0
source

All Articles