在对话框中初始化相机选项和图库

时间:2012-05-16 22:23:47

标签: android android-intent camera dialog

我使用意图初始化以下操作 enter image description here

现在除了这个画廊选项我也想要相机选项,我尝试了下面的代码,但没有工作

Intent cameraIntent = new Intent();
            cameraIntent.setType(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
             cameraIntent.setType("image/*");
             cameraIntent.setAction(Intent.ACTION_GET_CONTENT);
             //startActivityForResult(Intent.createChooser(intent, "Select Picture"),0);


        startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

它显示了图库选项,但没有显示相机.. 帮我弄清楚这个问题......

编辑:

 public boolean onCreateOptionsMenu(Menu menu) {
            // TODO Auto-generated method stub
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.menu, menu);
            return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // TODO Auto-generated method stub
            switch (item.getItemId()) {
            case R.id.cameraa:
                // Toast.makeText(this, "Save Project!", Toast.LENGTH_LONG).show();
                Intent intents = new Intent("android.media.action.IMAGE_CAPTURE");
                File photo = new File(Environment.getExternalStorageDirectory(),
                        "Pic.jpg");
                intents.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
                startActivityForResult(intents, 1);

                break;

            case R.id.gallery:
                // Toast.makeText(this, "Take Snapshot!", Toast.LENGTH_LONG).show();
                // ////This is gallery intent
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(
                        Intent.createChooser(intent, "Select Picture"), 0);
                break;
            }
            return true;
        }

1 个答案:

答案 0 :(得分:3)

嘿,此代码可能对您有所帮助,

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        intent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);

        startActivityForResult(intent, 0);