编译的SDK与源不同?

时间:2014-01-10 10:32:17

标签: android

我正在尝试在API17中使用类WifiP2pManager(android.net.wifi.p2p.WifiP2pManager.DialogListener)中的DialogListener接口(在API18和API19中删除)。在Android的源代码中,它显示为“Public”(WifiP2pManager.java):

 /**
 * Interface for callback invocation when dialog events are received.
 * see {@link #setDialogListener}.
 * @hide
 */
public interface DialogListener {

    /**
     * Called by the system when a request to show WPS pin is received.
     *
     * @param pin WPS pin.
     */
    public void onShowPinRequested(String pin);

    /**
     * Called by the system when a request to establish the connection is received.
     *
     * Application can then call {@link #connect} with the given config if the request
     * is acceptable.
     *
     * @param device the source device.
     * @param config p2p configuration.
     */
    public void onConnectionRequested(WifiP2pDevice device, WifiP2pConfig config);

    /**
     * Called by the system when this listener was attached to the system.
     */
    public void onAttached();

    /**
     * Called by the system when this listener was detached from the system or
     * failed to attach.
     *
     * Application can request again using {@link #setDialogListener} when it is
     * in the foreground.
     *
     * @param reason The reason for failure could be one of {@link #ERROR},
     * {@link #BUSY}, {@link #P2P_UNSUPPORTED} or {@link #NOT_IN_FOREGROUND}
     */
    public void onDetached(int reason);
}

但是在SDK内的编译类中它没有显示,如果你看看android.jar里面,你找不到WifiP2pManager.class,因此当我在我的Activity中尝试使用它时它会显示错误“无法解析符号”

我缺少什么?

1 个答案:

答案 0 :(得分:1)

在源代码中,您可以看到界面上方的注释@hide以及与之相关的方法:

 /**
 * Interface for callback invocation when dialog events are received.
 * see {@link #setDialogListener}.
 * @hide
 */
public interface DialogListener {

这意味着它下面的东西是隐藏的,在公共API中无法访问。

Android开发人员不希望您使用它。您可能想要寻找其他替代方案。由于它不是公共API的一部分,因此您无法依赖您的用户访问它,如果您试图规避它,那么您的应用将无法为这些用户服务。