Camera Preview not working on my G2

by Stephen Lebed » Wed, 20 Oct 2010 13:15:12 GMT


Sponsored Links
 'm trying to get the camera preview running on my G2.

This is the code I'm testing with, which was taken from the sample
code. It is using supplemental code supplied by Wu-Cheng, but its
still throwing an error


/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.sltools;

import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import java.io.IOException;
import java.util.List;

//
----------------------------------------------------------------------

public class CameraPreview extends Activity {
private Preview mPreview;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);

// Create our Preview view and set it as the content of our
activity.
mPreview = new Preview(this);
setContentView(mPreview);
}


}

//
----------------------------------------------------------------------

class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;

Preview(Context context) {
super(context);

// Install a SurfaceHolder.Callback so we get notified when
the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell
it where
// to draw.
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
// TODO: add more exception handling logic here
}
}

public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the
preview.
// Because the CameraDevice object is not a shared resource,
it's very
// important to release it when the activity is paused.
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}

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();

List<Size> sizes = parameters.getSupportedPreviewSizes();
Size optimalSize = getOptimalPrevi



Camera Preview not working on my G2

by TreKing » Wed, 20 Oct 2010 23:19:47 GMT


 



Does it not tell you which class was not found? That would be helpful :-)

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

--


Sponsored Links


Camera Preview not working on my G2

by Stephen Lebed » Thu, 21 Oct 2010 12:27:53 GMT


 Hi TreKing,

Two things

1) The logcat says Runtime exception: Cannot instantiate activity
ComponentInfo.  I'm not sure what that is supposed to mean.  Maybe you
could shed some insight on this.
2) How does someone change the discussion subject?  I can't believe
someone get comes in and hijacks my thread.

Best,
Stephen Lebed







--



Camera Preview not working on my G2

by TreKing » Thu, 21 Oct 2010 22:49:07 GMT


 



Is there any more to the log cat? Post the 5 - 10 lines above and below that
error. Also look for "cause by" in the message and post the 5 - 10 lines
above and below THAT.



I think that's yet another bug with Google Groups. I'm reading this thread
in Gmail and it's currently just you and me :-)

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

--



Other Threads

1. [ NotifyDataSetChanged / requery ] some question about it in a custom SimpleCursorAdapter.

Hi,

I have some questions about NotifyDataSetChanged() / requery() :

So,
I have a ListView with a custom SimpleCursorAdapter. Everything works
fine but when i go to another Intent by the OnItemClick() i got an
error  because it says that my Cursor in my getView() method is NULL.
i found that requery() does a refresh but it is now deprecated... but
here the doc says : "Performs the query that created the cursor again,
refreshing its contents."

First question :
- If I must perform the query AGAIN (because you get your cursor by
the DBAdapter before calling the constructor), why should the
constructor of the adapter get a Cursor ???

I found that NotifyDataSetChanged() should do the same things, and
have to be called in an event in the adapter, true ? But in my
project, i define my event in my ListActivity and not in the adapter.
Should i change it ?

I hope my english is not too bad, tell me if i have to explain
something a bit more !

Ty,

-- 

2. Print to serial port

I would like to print a string via the serial port in an Android
application.

This works fine using printf() in a regular Linux application written
in C, but I haven't been able to figure out how to do it from an
Android application written in Java.

I can also do it from a shell using something like "echo testString > /
dev/ttyS2".

The reason I would like to do this is for debugging purposes, so that
I don't need to have Eclipse open to look at the logCat file, or
similar methods.

Thank you for any input.

David

-- 

3. Usb host mode driver issue

4. Market package name on Xoom?

5. On emulator an Activity style with backgroundDimEnabled also dims GLSurfaceView output

6. Context differences

7. Jquery Mobile - Php - App Native