2011-10-12 109 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(); 
     } 
    } 
相關問題