1. @hide is used for things that need to be visible for various reasons but are not part of the published API. They will not be included in the documentation when it automagically extracts the API from the source.
    2. You should not use it at all since it’s not part of the API and the developers can remove it whenever they wish. They would even be within their rights, were they sadistically inclined, to replace it with a function that bricked the device it ran on (though maybe not in a strict legal sense).

    意思就是作者其实不想公开这个方法作为API,所以用@hide来隐藏它,我们就不能通过SDK的方式去直接调用它了。 而且如果这个方法被标为@hide,说明发布它的作者可以随便改这个方法,就算它的改动可以让你的程序直接死掉,也没关系!

    Android has two types of APIs that are not accessible via SDK.

    The first one is located in package com.android.internal. The second API type is a collection of classes and methods that are marked with the @hide Javadoc attribute.

    Starting from Android 9 (API level 28), Google introduces new restrictions on the use of non-SDK interfaces, whether directly, via reflection, or via JNI. These restrictions are applied whenever an app references a non-SDK interface or attempts to obtain its handle using reflection or JNI.

    But before API level 28, the hidden methods could still be accessed via Java reflection. The @hideattribute is just part of Javadoc (droiddoc also), so the @hide just simply means the method/class/field is excluded from the API docs.

    For example, the checkUidPermission() method in ActivityManager.java uses @hide:

    1. /** @hide */
    2. public static int checkUidPermission(String permission, int uid) {
    3. try {
    4. return AppGlobals.getPackageManager()
    5. .checkUidPermission(permission, uid);
    6. } catch (RemoteException e) {
    7. // Should never happen, but if it does... deny!
    8. Slog.e(TAG, "PackageManager is dead?!?", e);
    9. }
    10. return PackageManager.PERMISSION_DENIED;
    11. }

    However, we can call it by reflection:

    Class c;
    c = Class.forName("android.app.ActivityManager");
    Method m = c.getMethod("checkUidPermission", new Class[] {String.class, int.class});
    Object o = m.invoke(null, new Object[]{"android.permission.READ_CONTACTS", 10010});