2011-10-12 111 views
0

在camera.java中,我需要在系统中获取属性。然而,我无法导入android.os.SystemProperties,编译相机总是抱怨:无法在相机应用程序中导入android.os.SystemProperties

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

在camera.java的开始,我包括:

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

看来SystemProperties不是机器人.os包,但我已经检查了框架源代码,它确实在其中。

这发生在相机应用程序。我以这种方式使用SystemProperties在packages/app目录下发现了很多应用程序。这真的很奇怪。

+0

请参阅:http://stackoverflow.com/q/2641111/648313 – Idolon

回答

1

SystemProperties类设置为'隐藏'注释。
所以你想在应用层使用这个类, 你必须使用refelection。

SystemProperties类的定义如下。

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 
+0

谢谢。什么是反思,以及如何使用SystemProperties? Mms应用程序也只是导入它,但没关系。 – pengguang001

+1

我找到了原因!在Camera/Android.mk中,LOCAL_SDK_VERSION:= current,这会阻止我们使用HIDE接口。注释这一行将使编译通过。 – pengguang001

1

我遇到同样的问题,因为你有我使用下面的代码,并通过使用refelection解决问题。希望这会有所帮助

//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(); 
     } 
    } 
相关问题