13

Is it possible to use methods with @hide annotation without recompiling the sdk?

Note: I know I am not supposed to use this methods etc.

m0s
  • 4,250
  • 9
  • 41
  • 64

2 Answers2

10

Yes it is, reflection solves a whole lot of problems... And good to know you know you're not supposed to use them :)

Gilead
  • 1,516
  • 2
  • 18
  • 26
  • Can you show an example how to override a method at runtime using reflection? – m0s Feb 09 '11 at 22:45
  • 3
    @m0s: You can't override a method at runtime using reflection. And, to emphasize the point, you are not supposed to be using these methods, let alone override them. – CommonsWare Feb 09 '11 at 23:15
  • Override? I don't think that's possible but then I never checked. For an example how to _use_ one please see http://stackoverflow.com/questions/2660968 – Gilead Feb 09 '11 at 23:15
  • 1
    DO NOT DO THIS. It's not just "you are not supposed to use them," it is "an app relying on this will randomly break on different devices and platform versions" because there is no guarantee that these private symbols will remain. – hackbod Feb 10 '11 at 04:14
  • 1
    To be clear -- when we are doing compatibility testing with new versions of the Android platform, if we have an app that is breaking and see anywhere it is using private APIs, we *stop* testing it and consider it a broken app, end of story. You have a very good chances of painfully shooting yourself in the foot by using private APIs. – hackbod Feb 10 '11 at 04:16
  • 1
    So does that mean that apps with a WebView that fully works (i.e. supports file inputs in forms) are not supposed to exist? Or is there a way to accomplish that without overriding hidden methods like in m0s' answer? – matteo Apr 22 '14 at 12:53
  • how i can checkou this above path out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar – Bunny Aug 17 '20 at 13:13
5

Yes it is possible to use those methods. In my case I had to override a hidden method, specifically openFileBrowser method of WebChromeClient. To do so I simply added the method to the class body which extends WebChromeClient and everything worked fine. However if I placed @Override annotation eclipse would complain and refuse to compile... just removed it and everything compiled and worked fine. Gilead gets accepted answer since his "Yes it is" was indeed correct and pushed me to experiment.

m0s
  • 4,250
  • 9
  • 41
  • 64