简体   繁体   English

使用android相机拍照后,将用户带回之前的活动

[英]take user back to previous activity after taking photo using android camera

I am working on camera related app in android. 我正在研究与Android相机相关的应用。 What I want is when user takes photo he should be immediately take to previous activity where he was before. 我想要的是,当用户拍照时,他应该立即进行以前的活动。 Right now what my code does is when user takes a photo then two button appear at the bottom of the screen ie Save and Discard. 现在,我的代码要做的是当用户拍照时,屏幕底部会出现两个按钮,即“保存并放弃”。 So I do not want that. 所以我不想要那个。 When the picture is taken user should be directly navigate to previous activity. 拍照后,用户应直接导航至上一个活动。 How can acheive this? 如何做到这一点?

Here is my code 这是我的代码

public class CameraActivity extends Activity implements View.OnClickListener {
ImageView iv;
Button bCapture, bSetWall;
Intent i;
int CameraResult = 0;
Bitmap bmp;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initialize();
    InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
    bmp = BitmapFactory.decodeStream(is);
}

private void initialize() {
    iv = (ImageView)findViewById(R.id.ivCamera);
    bCapture = (Button)findViewById(R.id.bCapture);
    bSetWall = (Button)findViewById(R.id.bSetWall);
    bCapture.setOnClickListener(this);
    bSetWall.setOnClickListener(this);
}

public void onClick(View v) {
    switch(v.getId()) {
    case R.id.bCapture:
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, CameraResult);
        break;
    case R.id.bSetWall:
        try {
            getApplicationContext().setWallpaper(bmp);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        break;
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        iv.setImageBitmap(bmp);
    }
}


}

The code you have right now will capture photos using an existing camera application. 您现在拥有的代码将使用现有的相机应用程序捕获照片。 That is, it is making use of an already existing Activity that belongs to some camera application that is installed on your device. 也就是说,它利用的是属于您设备上已安装的某些摄像头应用程序的现有活动。

That said, there is no way to manipulate Activity s that belong to other applications. 就是说,没有办法操纵属于其他应用程序的Activity You'll have to implement your own Camera Activity instead. 您必须改为实施自己的“ 相机活动”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM