Why not set your build target to API Level 14 and just call the method, wrapping your calls in a Build.VERSION.SDK_INT check? Why are you messing around with reflection games?
On Wed, Mar 6, 2013 at 7:21 PM, Qianqian Fang <[email protected]> wrote: > hi list > > I am working on a camera program where I want to call setAutoExposureLock() > is supported. To make this backward compatible, I used some sample code I > found online to check the presence of this method first. The code snippet is > below: > > ... > try{ > Class c = Class.forName("android.hardware.Camera"); > > Method spcwb = null; > Method[] m = c.getMethods(); > for (int i = 0; i < m.length; i++) { > if (m[i].getName().compareTo("setAutoExposureLock") == 0) { > spcwb = m[i]; > break; > } > } > if (spcwb != null) { > Object[] arglist = new Object[1]; > arglist[0] = tf; > spcwb.invoke(cm, arglist); > Log.i(TAG, "setAutoExposureLock: Called method"); > } else { > Log.i(TAG, "setAutoExposureLock: Did not find method"); > } > }catch(...){...} > > however, I tried this on both Nexus S (ICS 4.1) and Nexus 4 (ICS 4.2), the > above code returned "not found". Shouldn't setAutoExposureLock be supported > by 4.0.3 and newer? I directly called this method for my Nexus 4, it worked. > But I'd like to make this work for older phones. > > I changed the class name to "android.hardware.Camera.Parameters", it did not > help. > > did I miss anything? > > Qianqian > > -- > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Android Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 4.6 Available! -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

