Use Reflection to allow for conditional compile.  This code snippet
might help, although it shows calling setFlashMode, the concept is the
same:

          Method methodSetFlashMode = null;
          Class<?>[] methodSetFlashModeSignature = new Class[]
{ String.class };

          List<Size> lSize = null;

          try
          {
                  methodSetFlashMode =
params.getClass().getMethod("setFlashMode",
methodSetFlashModeSignature);
          }
          catch (NoSuchMethodException nsme)
          {
          }


          if (methodSetFlashMode != null)
          {
                Object[] oArgs = new Object[1];
                oArgs[0] = "off";
                methodSetFlashMode.invoke(params, oArgs);
          }



On Jan 19, 3:21 pm, tikky <[email protected]> wrote:
> All,
> I am developing an app that uses the phonecamera, and I want to set
> the Flash Mode, if flash exists.
> From documentation, it looks like I need to 
> callCamera.Parameters.getFlashMode() and check if it returns null to
> determine if flash exists.
> Note: getFlashMode() is supported from API level 5
>
> However, when I try to run this app on a phone with cupcake, I get an
> error:
> 01-19 14:02:43.404: ERROR/dalvikvm(18891): Could not find method
> android.hardware.Camera$Parameters.getFlashMode, referenced from
> method ...
>
> I tried to call this code based on SDK version as follows, but that
> does not work either. Looks like there is a class verification  thats
> fails at init:
>
> import android.os.Build.VERSION;
> ....
>       int mSdkVersion = VERSION.SDK_INT;
>      Camera.Parameters params = mCamera.getParameters();
>       if (mSdkVersion >=5 && params.getFlashMode()!=null){
>                         
> params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);//set auto
> flash
>       }
>
> So now I am wondering if there is any other way to check if flash
> exists? or is there a way to conditionally compile code based on
> mSdkVersion?

-- 
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

Reply via email to