reflector methods

elitevenkat

Active Member
Licensed User
Longtime User
Hi,
Where can i find the list of valid/supported methods that can be passed like

r.RunMethod("getITelephony")
r.RunMethod("endCall" etc

venkat
 

warwound

Expert
Licensed User
Longtime User
Here's some auto generated refence from the Reflection library:
Reflection
Comment: This library contains a Reflector object that allows access to methods and fields
of Android objects that are not exposed to the Basic4Android language. It does this
by means of a facility called "Reflection" that uses meta-data for objects that is
included in the application package and allows dynamic access to fields and methods
at runtime.

GetActivity and GetActivityBA in this library only work for Basic4android 2.00 and higher.
Use version 2.1 of this library for earlier versions of Basic4android.

The specifications for the primitive Java types recognised by this object are
"java.lang.boolean", "java.lang.byte", "java.lang.char", "java.lang.short",
"java.lang.int", "java.lang.long", "java.lang.float", and "java.lang.double"
Note the lower-cased names. The single uppercase letter representation, as
listed for arrays below, is also recognised.

The specifications for boxed primitive Java types which are true objects are
"java.lang.Boolean", "java.lang.Byte", "java.lang.Char", "java.lang.Short",
"java.lang.Int", "java.lang.Long", "java.lang.Float", and "java.lang.Double"
Note the upper-cased names.

The specifications for arrays of primitive types is a number of square left brackets
corresponding to the rank of the array followed by a single letter indicating the type.
B represents the byte primitive type, S represents the short primitive type,
I represents the int primitive type, J represents the long primitive type,
F represents the float primitive type, D represents the double primitive type,
C represents the char primitive type, Z represents the boolean primitive type.
So a two dimension integer array is represented by "[[I".

The specifications for arrays of objects is similar but with the single letter replaced
the letter "L", followed by the class name terminated by a semicolon ";".
So a single dimension array of strings is represented by "[Ljava.lang.String;"
Author: Andrew Graham
Version: 2.2
  • Reflector
    Fields:
    • Target As Object
      This field holds the object that is being reflected upon. The target object is
      assigned to this field where it can then be manipulated as required.
    Methods:
    • CreateObject (type As String) As Object
      Creates and returns a new object of the specified type using the default constructor.
    • CreateObject2 (type As String, args() As Object, types() As String) As Object
      Creates and returns new object of the specified type using the constructor that matches
      the array of type names given and passing it the arguments provided.

      The array of type names is needed in order to find the correct constructor because
      primitives passed in the Args array are boxed and so CreateNew cannot tell whether
      to look for a target constructor that accepts a primitive parameter type or a boxed
      primitive object type.
    • GetActivity As Activity
      Returns the current activity if any.
      To avoid memory leaks this should not be used by a Reflector that is a Process object.
      To use this requires a knowledge of the structure of a Basic4android application.
    • GetActivityBA As BA
      Returns the Activity BA of the current activity.
      To avoid memory leaks this should not be used by a Reflector that is a Process object.
      To use this requires a knowledge of the structure of a Basic4android application.
    • GetArray (indeces() As Int) As Object
      Returns the Object at the position(s) in an array specified by the contents of indeces.
      indeces must be an integer array of the same rank as the Target array or an error will occur.
    • GetB4AClass (component As String) As Class
      Returns the Java Class for the specified B4A Activity, Service or Code module.
      To use this requires a knowledge of the structure of a Basic4android application.
    • GetContext As Context
      Returns the Context of the Process to which the Reflection object belongs.
      This is the Application object returned from Activity.getApplicationContext().
    • GetField (field As String) As Object
      Returns the value of the field of the current target. Protected and private fields
      may be accessed if allowed by any security manager which may be present.
      Target must be an instance of a Class, not a Class object.
    • GetField2 (fieldinfo As Field) As Object
      Returns the value of the field of the current target.
      Target must be an instance of a Class, not a Class object.
    • GetFieldInfo (field As String) As Field
      Finding a field from its string representation is expensive so this method can be used
      to get the Field information object and save it for multiple accesses of the same field.
      Protected and private fields may be accessed if allowed by any security manager which may be present.
    • GetMethod (method As String, types() As String) As Method
      Finding a method from its string representation is expensive so this method can be used
      to get the Method information object and save it for multiple invocations of the same method.

      The String array of type names is needed in order to find the correct variant of the method.
    • GetMostCurrent (component As String) As Object
      Returns the current instance for the specified B4A Activity or Service module.
      This might return null if the Activity or Service is not instantiated.
      Note that Code modules do not have a current instance.
      To use this requires a knowledge of the structure of a Basic4android application.
    • GetProcessBA (component As String) As BA
      Returns the processBA instance for the specified B4A Activity or Service module.
      To use this requires a knowledge of the structure of a Basic4android application.
    • GetProxy (interfacenames() As String, b4asubname As String) As Proxy
      In Java you can generate an interface at runtime and have it run a pre-compiled method.
      Many events in Android are handled by an interface that typically has an "onXxxxx" method
      that is called with some parameters relevant to the event. The interface is typically
      set on an object using that objects "setOnXxxxxListener" method.

      This GetProxy method dynamically creates a proxy instance that implements one or more
      specified interfaces and which contains the code to call a specified Basic4android Sub
      when any of the interface methods are called.

      Typically this instance will implement one or more listeners and will then be assigned
      to an object instance using RunMethod4 and its setOnXxxxxListener method.

      When a method of one of the specified interfaces is called the proxy will call the specified
      Basic4android Sub passing the method name as a string and any arguments in an object array.

      Note that interfaces declared as internal to a class will need a "$" instead of a "." as their
      final separator and all interfaces need to be fully qualified.
      e.g android.view.View$OnTouchListener

      The Basic4android Sub called must have the signature
      Sub WhateverName(method As String, anyargs() As Object) As Object
    • GetPublicField (field As String) As Object
      Returns the value of the public field of the current target.
      This is more efficient than GetField but can only access public fields.
      Target must be an instance of a Class, not a Class object.
    • GetStaticField (classname As String, field As String) As Object
      Returns the value of the specified static field of the specified class.
      Protected and private fields may be accessed if allowed by any security manager
      which may be present.
      Static fields may also be accessed with GetField and an instance of the class.
    • InvokeMethod (instance As Object, method As Method, args() As Object) As Object
      Invoke the provided Method on the provided object instance and return the result.
    • RunMethod (method As String) As Object
      Runs the specified method on the current target. Protected and private methods
      may be accessed if allowed by any security manager which may be present.
    • RunMethod2 (method As String, arg1 As String, type1 As String) As Object
      Runs the specified method on the current target passing it the argument provided.
      Protected and private methods may be accessed if allowed by any security manager
      which may be present.
    • RunMethod3 (method As String, arg1 As String, type1 As String, arg2 As String, type2 As String) As Object
      Runs the specified method on the current object passing it the arguments provided.
      Protected and private methods may be accessed if allowed by any security manager
      which may be present.
    • RunMethod4 (method As String, args() As Object, types() As String) As Object
      Runs the specified method on the current target passing it the arguments provided.
      Protected and private methods may be accessed if allowed by any security manager
      which may be present.

      The String array of type names is needed in order to find the correct method because
      primitives passed in the Args array are boxed and so RunMethod cannot tell whether to
      look for a target method that accepts a primitive parameter type or a boxed primitive
      object type.
    • RunPublicmethod (Method As String, Args() As Object, types() As Class) As Object
      Runs the specified method on the current target passing it the arguments provided.
      This is more efficient that RunMethd4 but the method must be public.

      The String array of type names is needed in order to find the correct method because
      primitives passed in the Args array are boxed and so RunMethod cannot tell whether to
      look for a target method that accepts a primitive parameter type or a boxed primitive
      object type.
    • RunStaticMethod (classname As String, method As String, args() As Object, types() As String) As Object
      Runs the specified static method of the specified class passing it the arguments provided.
      Protected and private methods may be accessed if allowed by any security manager
      which may be present.

      The String array of type names is needed in order to find the correct method because
      primitives passed in the Args array are boxed and so RunMethod cannot tell whether to
      look for a target method that accepts a primitive parameter type or a boxed primitive
      object type. For methods that take no parameters Null may passed for args and types.
    • SetArray (indeces() As Int, value As String, type As String)
      Set the position(s) in an array specified by the contents of indeces to the spcified value.
      indeces must be an integer array of the same rank as the Target array or an error will occur.
    • SetArray2 (indeces() As Int, value As Object)
      Set the position(s) in an array specified by the contents of indeces to the specified value.
      indeces must be an integer array of the same rank as the Target array or an error will occur.
    • SetField (field As String, value As String, type As String)
      Sets the specified field of the current target to the value provided. Protected and
      private fields may be accessed if allowed by any security manager which may be present.
      Target must be an instance of a Class, not a Class object.
    • SetField2 (field As String, value As Object)
      Sets the specified field of the current target to the value provided. Protected and
      private fields may be accessed if allowed by any security manager which may be present.
      Target must be an instance of a Class, not a Class object.
    • SetField3 (fieldinfo As Field, value As String, type As String)
      Sets the specified field of the current target to the value provided.
      Target must be an instance of a Class, not a Class object.
    • SetField4 (fieldinfo As Field, value As Object)
      Sets the specified field of the current target to the value provided.
      Target must be an instance of a Class, not a Class object.
    • SetOnClickListener (sub As String)
      Target must be a View of some sort.
      In most cases Basic4Android will have already exposed this as a Click event.
      Sets the OnClickListener of the view to a Sub that must have a signature of
      Sub Whatever(viewtag As Object).
    • SetOnCreateContextMenuListener (sub As String)
      Target must be a View of some sort.
      This is included for completeness of all the Listeners that class View supports.
      Sets the OnCreateContextMenuListener of the view to a Sub that must have a signature of
      Sub Whatever(viewtag As Object, menu As Object, menuinfo As Object)
    • SetOnFocusListener (sub As String)
      Target must be a View of some sort.
      Sets the onFocusChangeListener of the view to a Sub that must have a signature of
      Sub Whatever(viewtag As Object, focus As Boolean).

      You should make sure not to call DoEvents, Msgbox or any modal Dialog inside this
      event as it will fail in Android 4.0.3 and above.

      It may also fail if Debug is paused in the event in Android 4.0.3 and above.
    • SetOnKeyListener (sub As String)
      Target must be a View of some sort.
      Sets the onKeyListener of the view to a Sub that must have a signature of
      Sub Whatever(viewtag As Object, keycode As Int, keyevent As Object) As Boolean.

      This Sub must return True if it wants to consume the event or False otherwise.
    • SetOnLongClickListener (sub As String)
      Target must be a View of some sort.
      In most cases Basic4Android will have already exposed this as a LongClick event.
      Sets the OnLongClickListener of the view to a Sub that must have a signature of
      Sub Whatever(viewtag As Object) As Boolean.

      This Sub must return True if it wants to consume the event or False otherwise.
    • SetOnTouchListener (sub As String)
      Target must be a View of some sort.
      Sets the onTouchListener of the view to a Sub that must have a signature of
      Sub Whatever (viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean.

      This Sub must return True if it wants to consume the event or False otherwise.

      You should make sure not to call DoEvents, Msgbox or any modal Dialog inside this
      event as it will fail in Android 4.0.3 and above.

      It may also fail if Debug is paused in the event in Android 4.0.3 and above.
    • SetPublicField (field As String, value As String, type As String)
      Sets the specified field of the current target to the value provided.
      This is more efficient than SetField but can only access public fields.
      Target must be an instance of a Class, not a Class object.
    • SetPublicField2 (field As String, value As Object)
      Sets the specified field of the current target to the value provided.
      This is more efficient than SetField but can only access public fields.
      Target must be an instance of a Class, not a Class object.
    • SetStaticField (classname As String, field As String, value As String, type As String)
      Sets the specified static field of the specified class to the value provided.
      Protected and private fields may be accessed if allowed by any security manager
      which may be present.
      Static fields may also be accessed with SetField and an instance of the class.
    • SetStaticField2 (classname As String, field As String, value As Object)
      Sets the specified static field of the specified class to the value provided.
      Protected and private fields may be accessed if allowed by any security manager
      which may be present.
      Static fields may also be accessed with SetField and an instance of the class.
    • TargetRank As Int[]
      Returns an int array whose length is the number of dimensions of the array and whose contents
      are the length of the first element of each array dimension.
      A zero length integer array is returned if Target is not an array.
    • ToString As String
      Returns the result of running the "toString()" method of the current object.
    Properties:
    • IsNull As Boolean [read only]
      Returns True if the prsent value of Target is Null.
    • TypeName As String [read only]
      Returns the name of the class of the current object.
    • Version As Double [read only]
      Returns the version number of the library.

Martin.
 

elitevenkat

Active Member
Licensed User
Longtime User
Hi,

Dear warwound,

Thanks for your reply.

What i need is a complete callable method list that could be passed to runmethod like "endcall". The info you had provided is already available in lib documentation!.
 

warwound

Expert
Licensed User
Longtime User
Hi,

Dear warwound,

Thanks for your reply.

What i need is a complete callable method list that could be passed to runmethod like "endcall". The info you had provided is already available in lib documentation!.

Ah now i understand what you're asking!
The Android documentation is the only thing i can think of - it's documents all classes and all methods that each class supports.

There may well be a way to use the Reflection library to get a list of all public methods that a class supports - take a look a look here: java - Can I get all methods of a class? - Stack Overflow

Martin.
 
Top