内置的照相机程序在manifest定义了下面的intent filter
- <intent-filter>
- <action android:name="android.media.action.IMAGE_CAPTURE" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
<intent-filter> <action android:name="android.media.action.IMAGE_CAPTURE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
所以只需要用对应的intent启动就可以了
下面的android.provider.MediaStore.ACTION_IMAGE_CAPTURE = "android.media.action.IMAGE_CAPTURE";
- public class CameraIntent extends Activity {
- final static int CAMERA_RESULT = 0;
- ImageView mImagevView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.ch1);
- Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
- startActivityForResult(i, CAMERA_RESULT);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if(resultCode == RESULT_OK){
- //get extras from the intent
- Bundle extra = data.getExtras();
- //get the returned image from the extras
- Bitmap b = (Bitmap)extra.get("data");
- mImagevView = (ImageView)findViewById(R.id.returnedImageView);
- mImagevView.setImageBitmap(b);
- }
- }
- }