0

我正在使用意图来初始化以下操作 在此处输入图像描述

现在除了这个画廊选项我还想要相机选项,我尝试了以下代码但没有用

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;
        }
4

1 回答 1

3

嘿,这段代码可能对你有帮助,

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

        startActivityForResult(intent, 0);
于 2012-05-17T05:38:45.790 回答