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. Is it possible to run ADB shell command from inside an Android app

I wanted to start instrumentation from another app and realized that
StartInstrumentation function is available just for that. Thanks
everyone.







--~--~---------~--~----~------------~-------~--~----~

2. Java Compatibility problems with getFields method in Android java.lang.Class

And maybe javac itself changed the order of declarations when building the
.class file.
implementation-specific really means you can't rely on it.







--~--~---------~--~----~------------~-------~--~----~

3. Exception bitmap size exceeds VM budget

4. Java Compatibility problems with getFields method in Android java.lang.Class

5. How to call shell script from JNI?

6. Problem reading file

7. How to look up addresses (geocoding Q)?