Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old January 6th, 2010, 04:52 AM   #1 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2010
Posts: 17
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Camera Preview api demo

Hello everyone. I'm completely new to android, so hopefully someone can help me with this

I'm trying to run the Camera Preview api demo from the android website emulator (set to android 1.5), but i keep getting error the "application has stopped unexpectedly" error. Logcat says the following:

01-05 21:13:24.550: WARN/ServiceManager(542): Permission failure: android.permission.CAMERA from uid=10035 pid=867
01-05 21:13:24.561: ERROR/CameraService(542): Permission Denial: can't use the camera pid=867, uid=10035
01-05 21:13:24.580: DEBUG/AndroidRuntime(867): Shutting down VM
01-05 21:13:24.590: WARN/dalvikvm(867): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
01-05 21:13:24.590: ERROR/AndroidRuntime(867): Uncaught handler: thread main exiting due to uncaught exception
01-05 21:13:24.610: ERROR/AndroidRuntime(867): java.lang.RuntimeException: Fail to connect to camera service

From what i read online, the permission error should be fixed by adding a line to the manifest, but that doesn't seem to work. I tried adding two different lines:
Code:
<uses-permission android:name="android.permission.CAMERA" />
and
Code:
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
But for both i still get the error. Does anyone see my problem?

Below is the main code. I didn't change anything in the layout file, and i only added the permission line to the manifold.

Code:
 
package nl.example.camerapreview;

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

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

public class CameraPreview extends Activity {    
    private Preview mPreview;

    @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("hoera");
        // Hide the window title.
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        // Create our Preview view and set it as the content of our activity.
        try{
            mPreview = new Preview(this);
            setContentView(mPreview);
            System.out.println("hoera");
            }
        catch(RuntimeException e){
            System.out.println(e.getMessage());
        }
    }

}

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

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();
        parameters.setPreviewSize(w, h);
        mCamera.setParameters(parameters);
        mCamera.startPreview();
    }

}

android88 is offline  
Reply With Quote
sponsored links
Old January 6th, 2010, 07:01 AM   #2 (permalink)
Member
 
eclipsed4utoo's Avatar
 
Join Date: Nov 2009
Location: Florence, SC
Posts: 435
 
Device(s): Motorola Droid
Carrier: Not Provided

Thanks: 9
Thanked 27 Times in 11 Posts
Default

can you post your manifest file?
__________________
If you like MotoTorch LED, you could Donate With Paypal toward its continued development.

You can also buy the Donation version of MotoTorch LED from the Android Market.

Use Barcode Scanner or Shop Savvy to scan my avatar.
eclipsed4utoo is offline  
Reply With Quote
Old January 6th, 2010, 07:04 AM   #3 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2010
Posts: 17
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just found the problem. It was in the manifest file
According to a tutorial the permission line needed to be within the <application> </application>, but it needed to be outside it.
Now it works
thanks for the reply
android88 is offline  
Reply With Quote
Old January 6th, 2010, 08:33 AM   #4 (permalink)
New Member
 
Join Date: Oct 2009
Posts: 8
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default

Yep it needs to be outside the application tags, that one stung me when I was starting too
draffodx is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:19 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.