访问多个按钮的相机

时间:2016-07-06 20:50:10

标签: java android

如何设置多个按钮来访问相机并保存照片?

我已经弄清楚如何让一个按钮执行此任务,但无法弄清楚如何让多个按钮执行此操作。

到目前为止

我的Java代码:

package com.example.android.phototaker;


public class MainActivity extends AppCompatActivity {

    ImageView result;
    static final int REQUEST_IMAGE_CAPTURE = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button click = (Button)findViewById(R.id.signbutton);
        result = (ImageView)findViewById(R.id.imageView);

    }

    public void dispatchTakePictureIntent(View view) {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            result.setImageBitmap(imageBitmap);
        }
    }

}

1 个答案:

答案 0 :(得分:0)

多个按钮的意思是,不同的按钮打开相机? 如果是这样,您将需要为这些按钮添加onclick侦听器。