Packagecom.example.myandroidtest;ImportJava.lang.reflect.Constructor;ImportJava.lang.reflect.Field;ImportJava.lang.reflect.Method;ImportJava.lang.reflect.Modifier;ImportAndroid. R.integer;Importandroid.app.Activity;ImportAndroid.bluetooth.BluetoothAdapter;ImportAndroid.content.Context;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem; Public classMainactivityextendsbaseactivity {Class<?>Bclazz; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); LOG.E ("Tag", "=mainactivity=oncreate="); Try{ //gets the class object for the specified classesClass<?> clazz = Class.forName ("Android.app.Notification"); //clazz.newinstance (); //Get all ConstructorsConstructor[] Constructors=clazz.getconstructors (); for(Constructor constructor:constructors) {LOG.E ("Constructor reflection constructor:", ""); //Remove the first construction method. System.out.print (modifier.tostring (Constructor.getmodifiers ())); //----To print the prefix modifier for this construction methodSystem.out.print ("" +constructor.getname () + "(");//Print the name of the construction method//----Prints the parameters of the constructor method. Class[] Parametertypes=constructor.getparametertypes ();//constructs a method parameter set but the array type displays special for(intj=0;j<parametertypes.length;j++) {System.out.print (Parametertypes[j].getname ()); } System.out.println (")"); } //modifier-Class name-super Class name-interfaceLOG.E ("Notification Reflection package Name", Modifier.tostring (Clazz.getmodifiers ()) + "" +clazz.getpackage (). GetName () + "extends "+clazz.getsuperclass () +" implement "+clazz.getinterfaces (). GetClass (). GetName ()); //All FieldsField[] Fields=Clazz.getdeclaredfields (); //All public fields//field[] Fields=clazz.getfields (); for(Field field:fields) {//Array Special handling if(Field.gettype (). IsArray ()) {LOG.E ("Notification reflection Properties", Field.gettype (). Getcomponenttype () + "" +field.getname ()); } Else{LOG.E ("Notification reflection Properties", Field.gettype () + "" +field.getname ()); } } //All MethodsMethod[] Methods =Clazz.getdeclaredmethods (); //All public Methods//method[] Methods =clazz.getmethods (); for(Method method:methods) {LOG.E ("Notification Method Reflection Name", Modifier.tostring (Method.getmodifiers ()) + "" +method.getname ()); } }Catch(Exception e) {e.printstacktrace (); LOG.E ("Notification reflection Error", "Exception"); } Try{ //Gets the context object for the specified packageContext C = createpackagecontext ("Com.example.myandroidtest", Context.context_include_code |context.context_ignore_security); //get the Class objectBclazz = Class.forName ("Android.bluetooth.BluetoothManager"); //All ConstructorsConstructor[] Constructors=bclazz.getdeclaredconstructors (); //All public Constructors//constructor[] Constructors=bclazz.getconstructors (); for(Constructor constructor:constructors) {LOG.E ("Constructor reflection constructor:", ""); //Remove the first construction method. System.out.print (modifier.tostring (Constructor.getmodifiers ())); //----To print the prefix modifier for this construction methodSystem.out.print ("" +constructor.getname () + "(");//Print the name of the construction method//----Prints the parameters of the constructor method. Class[] Parametertypes=constructor.getparametertypes ();//constructs a method parameter set but the array type displays special for(intj=0;j<parametertypes.length;j++) {System.out.print (Parametertypes[j].getname ()); } System.out.println (")"); //constructor.newinstance (c);//instantiation of } //Parametric ConstructorsConstructor con = bclazz.getconstructor (Context.class); //create an object of it//Object maobject = Bclazz.newinstance ();//constructor no parameter instantiationLOG.E ("Calzz is null", "" + (bclazz==NULL)); LOG.E ("Bluetoothmanager Reflection Package Name", Modifier.tostring (Bclazz.getmodifiers ()) + "" +bclazz.getpackage (). GetName () + "Exten DS "+bclazz.getsuperclass () +" implement "+bclazz.getinterfaces (). GetClass (). GetName ()); //All FieldsField[] Fields=Bclazz.getdeclaredfields (); for(Field field:fields) {if(Field.gettype (). IsArray ()) {LOG.E ("Bluetoothmanager Reflection Properties", Field.gettype (). Getcomponenttype () + "" +field.getname ()); } Else{LOG.E ("Bluetoothmanager Reflection Properties", Field.gettype () + "" +field.getname ()); } } //get all the methodsMethod[] Methods =Bclazz.getdeclaredmethods (); for(Method method:methods) {LOG.E ("Bluetoothmanager method reflects name", "" +method.getname ()); if(Method.getname (). Equals ("Getadapter")) { //Execution MethodMethod.invoke (Con.newinstance (c)); } } }Catch(Exception e) {e.printstacktrace (); LOG.E ("Calzz is null", "" + (bclazz==NULL)); LOG.E ("Bluetoothmanager Reflection Error", "Exception"); } } }
"Android" reflex