Camera Preview on Motorola Droid

Our application displays a camera preview and it seems to work fine on all phones except for the Motorola Droid where we get a runtime exception when we set the camera parameters:

    java.lang.RuntimeException: setParameters failed
   at android.hardware.Camera.native_setParameters(Native Method)
   at android.hardware.Camera.setParameters(Camera.java:611)
   at com.highwaynorth.andrometer.CameraPreviewSurfaceView.surfaceChanged(CameraPreviewSurfaceView.java:57)
   at android.view.SurfaceView.updateWindow(SurfaceView.java:460)
   at android.view.SurfaceView.dispatchDraw(SurfaceView.java:287)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1525)

Here is the code for surfaceChanged() which is mostly taken from APIDemos

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
   // Now that the size is known, set up the camera parameters and begin
   // the preview.
   Camera.Parameters parameters = mCamera.getParameters();
   parameters.setPreviewSize(w, h);
   parameters.setPictureFormat(PixelFormat.JPEG);
   parameters.setPreviewFormat(PixelFormat.YCbCr_422_SP);
   parameters.setPreviewFrameRate(1);
   mCamera.setParameters(parameters);
   mCamera.startPreview();

}

Does anyone know what is wrong with how we are setting the parameters that would be causing the exception on the Motorola Droid?


Asked by: Paul531 | Posted: 20-01-2022






Answer 1

I can tell you your problem is with one of the following two lines:

parameters.setPreviewFormat(PixelFormat.YCbCr_422_SP);
parameters.setPreviewFrameRate(1);

I know this, because the rest of that code is just what I do in some camera samples in my book, and they've been tested on a DROID.

You may wish to use getSupportedPreviewFormats() and getSupportedPreviewFrameRates() on your Camera.Parameters object, to see if the device in question supports the format and frame rate you seek. Note that those methods are new to Android 2.0, so they'll work on the DROID/Milestone (and, presumably, the Nexus One), but nothing else at the time of this writing. If you are targeting older Android API versions, you'll need to use reflection or some classloading tricks to get these methods to work on Android 2.0 and be skipped on older versions.

Answered by: Julia990 | Posted: 21-02-2022



Answer 2

You should check what preview formats are available to make sure you can run on as many devices as possible.

It looks like DROID supports PixelFormat.YCbCr_422_I PixelFormat.YCbCr_420_SP

you can use the following method to get a list of available formats. getSupportedPreviewFormats()

Pixel Formats

Answered by: Alford825 | Posted: 21-02-2022



Answer 3

Another thing you may want to investigate:

I am experiencing this issue for devices running Motoblur and updated to 2.3 (especially Droid2, DroidX and Atrix with Verizon).

The Camera parameters were fine, but in layout/capture.xml the background of the ViewfinderView is set to transparent:

<com.google.zxing.client.android.ViewfinderView
   android:id="@+id/viewfinder_view" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:background="@color/transparent"
/>

Well, it looks that transparent for Motoblur on Android 2.3 is not that transparent...

removing

android:background="@color/transparent"

from the ViewFinder solved my problem.

Answered by: Chester650 | Posted: 21-02-2022



Similar questions

android - Motorola dext and Google maps

I am having an issue with my app, soley on the Moto DEXT. I have tried to reproduce on my Hero and the 1.5 emulator with no luck. The exception (see logcat snippet below) seems to be coming from within the system code, so I may be out of luck. Rough jist is, user presses the button, new MapActivity loads, they see the grid start then get a force close. On loading the MapActivity loads up a customised MyLo...


android - Motorola dext and Google maps

I am having an issue with my app, soley on the Moto DEXT. I have tried to reproduce on my Hero and the 1.5 emulator with no luck. The exception (see logcat snippet below) seems to be coming from within the system code, so I may be out of luck. Rough jist is, user presses the button, new MapActivity loads, they see the grid start then get a force close. On loading the MapActivity loads up a customised MyLo...


Problem saving file on Motorola Droid, Android 2.1?

Two of my users have reported a problem with my Android application, OftSeen Gestures. Both of them are using a Motorola Droid. The app saves a text file which is just a list of gesture names and phone numbers, both strings. It saves the file to the private data area. I don't know that it is this code that is failing but they report the assigned numbers disappearing after the phone comes out of screen sleep. Since the file...


motorola droid - How big is an android phone's screen?

How big is the smallest motorola android's screen, in pixels? I want to know what size I need to make my graphic without it being too distorted by the fill_parent.


android - Images in a web view on a Motorola Droid. What size?

I am developing a Java Android application that displays web content from the assets folder in a web view. I had no problem getting this content to display in the application but I am confused as to why my images are not displaying properly. I'm working with a Motorola Droid that is supposed to be 480x854 resolution. When I create banner images using these dimensions and attempt to display them in the web view they're enor...


android - google maps glitch on motorola phones

On the Motorola Bravo, at the left bottom of a MapView, there is an ugly orange square rather than the google logo. I notice this not only on my app, but on say, Yelp -- see screen shot: Has anyone else seen this, and is there a workaround? I don't know if it happens on other motorola phones, but I'm guessing it does because there is another,...


android app unable run in Motorola droid

Hi i am new to android. i developed an android app using 2.1 version in eclipse Ganymede. i used SQLite data base to store data and it will show the stored values when loading page My app is running perfectly in Sony Ericsson Xperia but it was not working in motorola droid which is having os Android 2.1 i dont know what is the cause. is there need to give any special permissions in manifest file to run app in droid or oth...


android - Motorola Xoom Browser Specs

Does anyone know or have references for the browser used on Motorola Xoom.. I mean which browser, version, engine ,viewport, etc...


android - Need helps in Motorola ATRIX

I need Motorola ATRIX emulator skin for testing my application,anybody knows please give me. Thanks to all


android - Motorola Xoom PDF/PPT View

I need to develop a Sales app specifically targeted for Android on Motorola Xoom. The app needs to display some pdf and ppt files bundled within the apk itself. The documents should display from within the app itself as the document viewer UI screen should be customisable (client logo etc.) so calling an Intent for some preinstalled document renderer is not an option. I then tried displaying the pdf in Webview but with no ...


Android: Motorola XT720 Exchange Account Problem

I have an app published on Android Market that can save contacts to different accounts. This app allows users to choose an account to save a contact to. But a lot of Motorola users report that Exchange account is not available in the list of possible accounts. Here's a piece of code I use to get sync adapters which can save contacts: final Set&lt;String&gt; accountTypeSet = new HashSet&lt;String&gt;...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top