Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't import android.os.SystemProperties in Camera app

Tags:

android

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.

like image 796
pengguang001 Avatar asked May 23 '26 18:05

pengguang001


2 Answers

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
like image 173
IvoryCirrus Avatar answered May 25 '26 06:05

IvoryCirrus


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();
        }  
    }
like image 22
luodewu Avatar answered May 25 '26 08:05

luodewu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!