android, Method invoke problem when getting result
I am try to use reflection to invoke the "List Camera.Parameters.getSupportedFocusModes()" function with the following code开发者_运维百科s:
Camera.Parameters params = mCamera.getParameters();
Method method = params.getClass().getDeclaredMethod("getSupportedFocusModes", (Class[]) null);
Object o = method.invoke(params, (Object[]) null);
the log shows it does find the function, however, the result o is always null, why is that? Please help me out!
Works fine for me. Returned [auto, infinity]
Make sure that the device you are testing on is using API Level 5 or higher and that <uses-permission android:name="android.permission.CAMERA" />
is added to the AndroidManifest.xml.
Here's the code I used.
Camera camera = Camera.open();
Camera.Parameters params = camera.getParameters();
try
{
Method method = params.getClass().getDeclaredMethod("getSupportedFocusModes", (Class[]) null);
Object o = method.invoke(params, (Object[]) null);
Log.i("Camera Test", o.toString());
}
catch (Exception e)
{
e.printStackTrace();
}
Try using "getMethod"
Below is the sample using the same.
Method method = this.getFirstActivity().getClass().getMethod("didReceive", null);
method.invoke(this.getFirstActivity().getClass().newInstance(), null);
精彩评论