mercredi 6 octobre 2021

Cannot Access All the View fields Through Reflection

I am trying to access the Android View property mAttributes here. Since it is public property, I tried to access it like this.

View(this).mAttributes

But it didn't work. It says cannot resolve symbol mAttributes.

I tried to use reflection API to remove the annotation @ViewDebug.ExportedProperty from that property to see if it works that way.

However View(this).javaClass.declaredFields doesn't show that property at all.

Not just that, View(this).javaClass.declaredFields doesn't show some properties like private CharSequence mContentDescription; as well.

For example, if we take a look at Android View source code, here you can see a private property mContentDescription.

If you try accessing that field using reflection like below, it throws error saying No field mContentDescription in class Landroid/view/View; (declaration of 'android.view.View' appears in /system/framework/framework.jar!classes3.dex)

View(this).javaClass.getDeclaredField("mContentDescription")

I'm confused why reflection API returns only some of the declared fields.





Aucun commentaire:

Enregistrer un commentaire