`
liliang1222
  • 浏览: 158695 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

pro.Android Media--调用内置的照相机

 
阅读更多

内置的照相机程序在manifest定义了下面的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);
			
		}
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics