@SystemApi
,@PrivateApi
和@hide
根据这个提交,@SystemApi
是旧的@PrivateApi
的重命名。标记为@hide
的API不一定是@SystemApi
,但@SystemApi
需要@hide
。
有关@hide
javadoc注释的更多信息,请参见此帖子给出了一个很好的答案。
基于我自己的实验,一个(非系统应用程序)仍然可以使用Java反射访问@hide
API和字段,例如(来自此帖子):
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration config = new WifiConfiguration();
config.SSID = "AccessPointSSID";
Method method = manager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
method.invoke(manager, config, true);
但是使用Java反射尝试访问@SystemApi
的内容是不可能的(以下代码将触发invocationTargetException
):
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method method = manager.getClass().getMethod("getPrivilegedConfiguredNetworks");
List<WifiConfiguration> configs = (List<WifiConfiguration>)method.invoke(manager);
P.S.
在WifiManager
Java 代码中,setWifiApEnabled
和getPrivilegedConfiguredNetworks
API被定义为:
public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {
try {
mService.setWifiApEnabled(wifiConfig, enabled);
return true;
} catch (RemoteException e) {
return false;
}
}
和
@SystemApi
public List<WifiConfiguration> getPrivilegedConfiguredNetworks() {
try {
return mService.getPrivilegedConfiguredNetworks();
} catch (RemoteException e) {
return null;
}
}
@SystemApi
和@hide
注释(以前只有@hide
注释)的API仍然可以通过反射访问。在您的情况下,“InvocationTargetException”的详细信息是什么? - Oasis Feng@SystemApi
的行为与版本有关? - Moony Chou