当图像是Saved Eclipse时添加toast

时间:2016-01-31 15:04:37

标签: java android

我制作了可以拍照的应用。一旦用户点击"保存"我只想要一个吐司信息出现。

当前代码可以拍照,但我想在用户将图像保存到相机文件夹时实现下面的Toast代码。任何想法我会怎么做。

以下是拍摄照片的源代码:

static final int REQUEST_IMAGE_CAPTURE = 1;
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 0;
public void onClickbtnCamera(View v){
  Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
  Uri uriSavedImage=Uri.fromFile(
    new  File("/storage/emulated/0/DCIM/Camera","QR_"+timeStamp+ ".png"));
  imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
  startActivityForResult(imageIntent, 1);
}

我要展示的祝酒词:

Toast toast= Toast.makeText(getApplicationContext(),
             "Picture was taking", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 100, 0);
toast.show();

1 个答案:

答案 0 :(得分:1)

由于您使用的是startActivityForResult(),因此您将在活动内的onActivityResult()方法中获得回复。试试这个示例代码。

          @Override
          public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1) {

          //Check for succesful result code
          //replace getResources().getInteger(R.integer.success) with the actual resultCode
          if (resultCode == getResources().getInteger(R.integer.success)) {
            //Show your Toast when the result is a success.
            Toast toast = Toast.makeText(getApplicationContext(),
                "Picture was taking", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 100, 0);
            toast.show();
          }
        }
      }