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?
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.