views:

24

answers:

1

Hi all, I am try to use reflection to invoke the "List Camera.Parameters.getSupportedFocusModes()" function with the following codes:

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!

A: 

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();
}
jojaba
thanks for answering. the above code you used still returns nothing on my Desire.However, surprisingly, Object o = method.invoke(params) worked. any idea why is that? >.<Thank you again!
yee
I think that Object o = method.invoke(params) is the correct way to call a method without arguments. Not sure why the other way worked for me and not for you.
jojaba