Friday 15 January 2010

Taking a photo using the front camera on Android 2.1 and 2.2 -


I can take a photo with this code using the front camera in android gingerbread 2.3 and above Android: < / P>

  package com.system.settings; Import java.io.file; Import java.io.FileOutputStream; Import android.content.Context; Import android.content.pm.PackageManager; Import android.hardware.Camera; Import android.hardware.Camera.PictureCallback; Public class frontfoto implements imagecollect {Private stationary camera camera; Personal last reference references; Public FrontPhotos (Reference Reference) {this.context = context; } PictureTrack on Public Zero (byte [] data, android.hardware.Camera camera) {file's filefile = new file ("/ sdcard / FrontPhoto.jpg"); {FileOutputStream fos = Try New FileOutputStream (pictureFile); Fos.write (data); Fos.close (); } Catch (Throwable T) {}} Take Public Static Wide (Reference CTX) {if (Front Camera Project (CTX) == true) {camera.takePicture (empty, tap, new frontfoto (CTX)); }} Private Static Boolean Front Camera Present (Reference CTX) {if (ctx.getPackageManager). Hasistformer (PackageManager.FEATURE_CAMERA)) {Boolean results = False; Int numOfCameras = Camera.getNumberOfCameras (); For (int i = 0; i   

But I want to be able to use this code for 2.2 and 2.1 versions. To do this, I put the camera project in my project in 2.3 project, changed it and participated. But I get an error

  getNumberOfCameras can not find native method   

I read all the answers on this topic on this site. I also tried this code, but it also gives an error and it is not a universal method because it is only suitable for some devices:

  Camera Parameter parameter = mCamera.getParameters (); Parameters.set ("camera-id", 2); Parameters.setPreviewSize (640, 480); MCamera.setParameters (parameter);   

My question is: how to compatibility with older versions. In my project how to include all the methods used for camera class 2.3 and all the basic methods.

To do this, I placed the camera project in my project with 2.3 source, it Changed and participated.

It will not work with any framework class, let alone camera .

But I get an error getNumberOfCameras Basic method can not be found.

The reason for this is that Android will ignore your android.hardware.Camera class and will use your own to control the runtime classpath. , And Android's system class always takes precedence over the same name and package that is in your APK.

You can re-apply your copy to another package, but you will crash on all the original methods.

My question is: How to compatibility with older versions

You can not do Android 2.3 front-facing camera support before Was there.

Some device makers may have established front-facing cameras on their devices, and how many subsets of those manufacturers used developers, such as camera-id < / Code> Code that you showed above, using the Build class, you welcome all those instructions to find them, then apply those instructions where available .

How to incorporate all the methods in my project requires it by camera class 2.3 and by all the basic methods.

You can not make Android 2.3 magically front-facing camera support before the Android OS, no matter what you put in your project.

No comments:

Post a Comment