3

In camera.java, I need to get property in system. However, I can't import android.os.SystemProperties, compile camera always complains:

packages/apps/Camera/src/com/android/camera/Camera.java:53: cannot find symbol
symbol  : class SystemProperties
location: package android.os
import android.os.SystemProperties;

In the beginning of camera.java, I included:

import android.os.Message;
import android.os.MessageQueue;
import android.os.SystemClock;
import android.os.SystemProperties; /* (this is in line 53)*/

It seems SystemProperties is not in android.os package, but I have checked the frameworks source code, it's indeed in it.

This happen in camera app. I found many apps under packages/app dir using SystemProperties in this manner. It's really strange.

pengguang001
  • 4,045
  • 6
  • 27
  • 31

2 Answers2

4

SystemProperties class is setted 'hide' annotation.
So you want to use this class in application layer, you have to use refelection.

the definition of SystemProperties class is below.

package android.os;
/**
 * Gives access to the system properties store.  The system properties
 * store contains a list of string key-value pairs.
 *
 * {@hide}
 */
public class SystemProperties
IvoryCirrus
  • 622
  • 1
  • 4
  • 15
  • 1
    Thanks. What's reflection, and how to use SystemProperties? The Mms app also just import it, but it's ok. – pengguang001 Oct 12 '11 at 04:37
  • 1
    I found why! In Camera/Android.mk, LOCAL_SDK_VERSION := current, this prevent us using the HIDE interface. Comment this line will make compile pass. – pengguang001 Oct 12 '11 at 06:37
2

i have encounter the same problem as you have, and i use the code below, and solve the problem by using refelection. hope it would be help

//set SystemProperties as you want
public static void setProperty(String key, String value) {    
        try {    
            Class<?> c = Class.forName("android.os.SystemProperties");  
            Method set = c.getMethod("set", String.class, String.class);
            set.invoke(c, key, value );
        } catch (Exception e) {
            Log.d(LOGTAG, "setProperty====exception=");
            e.printStackTrace();
        }  
    }
luodewu
  • 21
  • 1