0

I am trying to use the hidden package manager method installPackage via reflections.

My major problem is that one of its parameters is another hidden class android.content.pm.IPackageInstallObserver. How can I get the TYPE of that class (not an instance of it)?

val cPackageManager = Class.forName("android.content.pm.PackageManager")
val cPackageInstallObserver = Class.forName("android.content.pm.IPackageInstallObserver")

// here I need the IPackageInstallObserver type as a parameter type to look up the method
val installPackageMethod = cPackageManager.getMethod("installPackage", Uri::class.java, cPackageInstallObserver::class.java, Integer.TYPE, String::class.java)

In the way above, cPackageInstallObserver::class.java resolves to only a Class but not the actual type I need.

Does anybody have a solution for that?

phoebus
  • 1,280
  • 1
  • 16
  • 36

1 Answers1

1

You just did a simple mistake here

Uri::class.java, cPackageInstallObserver, Integer.TYPE, String::class.java)

As cPackageInstallObserver is already a class you need, as Class.forName returns a Class type, but you used cPackageInstallObserver::class.java so it is just same as doing String.class.getClass() in java, so just Class.class.

GotoFinal
  • 3,585
  • 2
  • 18
  • 33
  • You were right thanks for pointing that out. Do you also know how I can create a class that implements that interface type? à la ```MyClass : cPackageInstallObserver() { /* ... */ }``` – phoebus Jul 31 '18 at 15:54
  • 1
    if this is an interface then lookup for Proxy classes, like here: https://stackoverflow.com/questions/51397139/how-to-create-a-callback-using-reflection-in-android – GotoFinal Jul 31 '18 at 18:20