Android 什么';新的@SystemApi注释的含义是什么,与@hide有什么区别吗?

Android 什么';新的@SystemApi注释的含义是什么,与@hide有什么区别吗?,android,annotations,Android,Annotations,Android最近在其SDK源代码中引入了@SystemApi。在效果上似乎与之前的@hide注释相同,因为它们也从SDK jar类中剥离 应用程序是否有可能以不同于旧的@hide API的方式调用它们 /** * Indicates an API is exposed for use by bundled system applications. * <p> * These APIs are not guaranteed to remain consistent releas

Android最近在其SDK源代码中引入了@SystemApi。在效果上似乎与之前的@hide注释相同,因为它们也从SDK jar类中剥离

应用程序是否有可能以不同于旧的@hide API的方式调用它们

/**
 * Indicates an API is exposed for use by bundled system applications.
 * <p>
 * These APIs are not guaranteed to remain consistent release-to-release,
 * and are not for use by apps linking against the Android SDK.
 * </p><p>
 * This annotation should only appear on API that is already marked <pre>@hide</pre>.
 * </p>
 *
 * @hide
 */
/**
*指示已公开API以供捆绑的系统应用程序使用。
*
*这些API不保证在不同版本之间保持一致,
*并且不供链接到Android SDK的应用程序使用。
*

*此注释应仅出现在已标记为@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);
*

* *@隐藏 */
@SystemApi
@PrivateApi
@hide
据介绍,
@SystemApi
是对旧的
@PrivateApi
的重命名。标有
@hide
的API不一定是
@SystemApi
,但
@SystemApi
需要
@hide

有关
@hide
javadoc注释的更多信息,请给出一个很好的答案

根据我自己的实验,one(非系统应用程序)仍然可以使用Java反射访问
@hide
API和字段,比如(从):

但是尝试使用Java反射访问
@SystemApi
东西是不可能的(以下代码将触发):

/**@隐藏*/
@SystemApi
公共列表getPrivilegedConfiguredNetworks(){
试一试{
返回mService.getPrivilegedConfiguredNetworks();
}捕获(远程异常){
返回null;
}
}

用@SystemApi注释的方法是用@hide注释的方法的子集。 这显然是内部团队(可能也是合作伙伴)的一个指标,表明这些方法是实际的API,尽管不是针对公共开发人员的

因此,@SystemApi方法将比@hide方法更稳定,在未来的任何时候都可以更改@SystemApi方法,而无需考虑兼容性,而且任何OEM都可以自行更改它们


如果您试图通过反射调用内部API,请始终选择@SystemApi方法,以提高将来的兼容性。

谢谢您的解释!在我的测试中,大多数带有
@SystemApi
@hide
注释(以前仅由
@hide
注释)的API仍然可以通过反射访问。在你的例子中,
InvocationTargetException
的详细信息是什么?我用安卓5.0在Nexus5上做了这个实验@我猜
@SystemApi
的行为与版本有关?我还用安卓5.0.2在Nexus5上测试了它。也许不同的API会有所不同。您能粘贴InvocationTargetException的详细消息吗?有没有办法使用@SystemApi注释调用函数?
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

Method method = manager.getClass().getMethod("getPrivilegedConfiguredNetworks");
List<WifiConfiguration> configs = (List<WifiConfiguration>)method.invoke(manager);
/**
 * Start AccessPoint mode with the specified
 * configuration. If the radio is already running in
 * AP mode, update the new configuration
 * Note that starting in access point mode disables station
 * mode operation
 * @param wifiConfig SSID, security and channel details as
 *        part of WifiConfiguration
 * @return {@code true} if the operation succeeds, {@code false} otherwise
 *
 * @hide Dont open up yet
 */
public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {
    try {
        mService.setWifiApEnabled(wifiConfig, enabled);
        return true;
    } catch (RemoteException e) {
        return false;
    }
}
/** @hide */
@SystemApi
public List<WifiConfiguration> getPrivilegedConfiguredNetworks() {
    try {
        return mService.getPrivilegedConfiguredNetworks();
    } catch (RemoteException e) {
        return null;
    }
}