无法连接到相机

时间:2014-05-23 13:27:50

标签: android camera imageview

我试图制作一个简单的项目,从相机捕获图像并保存在imageview中。但是,当我运行应用程序时,它说可以;连接到相机。我的代码到底有什么问题?

主要活动:

package com.example.cameraimage;



public class MainActivity extends Activity implements OnClickListener
{
Button button;
ImageView imageview;
Bitmap bitmap;
int data = 0;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK){

        Bundle extras = data.getExtras();
        bitmap = (Bitmap) extras.get("data");
        imageview.setImageBitmap(bitmap);

    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button = (Button) findViewById(R.id.button1);
    imageview = (ImageView) findViewById(R.id.imageView1);

    button.setOnClickListener(this); 
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    if (v.getId() == R.id.button1){
        Intent i = new       
Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, data);
    }
}

}

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.cameraimage"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />
 <uses-permission android:name="android.permission.CAMERA" />

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.cameraimage.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

LogCat是:

05-23 13:44:56.801: E/EmulatedCamera_GenyClient(111): receiveMessage: Unable to obtain         payload size: Try again
05-23 13:44:56.801: E/EmulatedCamera_GenyClient(111): doQuery Response to query 'connect' has failed: Try again
05-23 13:44:56.801: E/EmulatedCamera_GenyClient(111): queryConnect: Query failed: No error message
05-23 13:44:56.801: E/EmulatedCamera_GenyDevice(111): connectDevice: Connection to device 'back' failed
05-23 13:44:56.801: E/CameraClient(111): Could not open camera 0: -11
05-23 13:44:56.801: E/CameraClient(111): initialize: Camera 0: unable to initialize device: Try again (-11)
05-23 13:44:56.801: I/CameraClient(111): Destroying camera 0
05-23 13:44:56.801: E/CameraHolder(1456): fail to connect Camera
05-23 13:44:56.801: E/CameraHolder(1456): java.lang.RuntimeException: Fail to connect to camera service
05-23 13:44:56.801: E/CameraHolder(1456):   at android.hardware.Camera.native_setup(Native Method)
05-23 13:44:56.801: E/CameraHolder(1456):   at android.hardware.Camera.<init>(Camera.java:343)
05-23 13:44:56.801: E/CameraHolder(1456):   at android.hardware.Camera.open(Camera.java:303)
05-23 13:44:56.801: E/CameraHolder(1456):   at com.android.camera.CameraHolder.open(CameraHolder.java:131)
05-23 13:44:56.801: E/CameraHolder(1456):   at com.android.camera.Util.openCamera(Util.java:267)
05-23 13:44:56.801: E/CameraHolder(1456):   at com.android.camera.Camera$4.run(Camera.java:1100)
05-23 13:44:56.801: E/CameraHolder(1456):   at java.lang.Thread.run(Thread.java:841)

0 个答案:

没有答案