內建的照相機程式在manifest定義了下面的intent filter
Xml代碼
- <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";
Java代碼
- 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);
-
- }
- }
- }