2011-04-30 52 views
3

我可以使用Intent调用摄像头吗?如果是,那么intent和Camera之间有什么区别? cam = Camera.open(); 我写上面的代码,但我得到一个错误。 我该如何解决这个错误?我可以使用Intent调用摄像头吗?

+0

这从Android开发者文档中有你可能需要的任何其他细节:http://developer.android.com/guide/topics/media/camera.html – 2015-05-19 03:15:50

回答

5

当然

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(cameraIntent, CAMERA_REQUEST); 

您将获得的数据onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (requestCode == CAMERA_REQUEST) { 
      Bitmap photo = (Bitmap) data.getExtras().get("data"); 
      imageView.setImageBitmap(photo); 
     } 

清单添加以下功能。

**<uses-feature android:name="android.hardware.camera"/>** 
0

试试这个...

Intent intent = new Intent(); 
intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE); 
1

你有没有在你的AndroidManifest.xml中所需的权限?

<uses-permission android:name="android.permission.CAMERA" /> 
<uses-feature android:name="android.hardware.camera" /> 
<uses-feature android:name="android.hardware.camera.autofocus" />