-2

I have the following method for the button onclick listener

 titleBar.setRightBtnOnclickListener(v -> {
        savePicture();
        PublishActivity.openWithPhotoUri(this, Uri.fromFile(photoPath));
    });

i want to be able to pass the filepath of the photo to another activity here i am saving the bitmap

private void savePicture(){
    //加滤镜
    final Bitmap newBitmap = Bitmap.createBitmap(mImageView.getWidth(), mImageView.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas cv = new Canvas(newBitmap);
    RectF dst = new RectF(0, 0, mImageView.getWidth(), mImageView.getHeight());
    try {
        cv.drawBitmap(mGPUImageView.capture(), null, dst, null);
    } catch (InterruptedException e) {
        e.printStackTrace();
        cv.drawBitmap(currentBitmap, null, dst, null);
    }
    //加贴纸水印
    EffectUtil.applyOnSave(cv, mImageView);

    new SavePicToFileTask().execute(newBitmap);
}

Then here am using the async

public class SavePicToFileTask extends AsyncTask<Bitmap,Void,String>{
    Bitmap bitmap;
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        showProgressDialog("图片处理中...");
    }

    @Override
    protected String doInBackground(Bitmap... params) {
        String fileName = null;
        try {
            bitmap = params[0];

            String picName = TimeUtils.dtFormat(new Date(), "yyyyMMddHHmmss");
             fileName = ImageUtils.saveToFile(FileUtils.getInst().getPhotoSavedPath() + "/"+ picName, false, bitmap);
            photoPath = new File(fileName);
        } catch (Exception e) {
            e.printStackTrace();
            toast("图片处理错误,请退出相机并重试", Toast.LENGTH_LONG);
        }
        return fileName;
    }

    @Override
    protected void onPostExecute(String fileName) {
        super.onPostExecute(fileName);
        dismissProgressDialog();
        if (StringUtils.isEmpty(fileName)) {
            return;
        }
    }
}

so am having trouble on how to get the photo path and then using Uri pass it to the next activity thanks guys

  • Try looking at https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application – Red wine Aug 16 '18 at 22:18
  • Possible duplicate of [How do I pass data between Activities in Android application?](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – James Aug 16 '18 at 22:45

1 Answers1

0

You should pass the filename as a String using an Intent.

Intent intent = new Intent(getBaseContext(), NEWACTIVITYNAME.class);
intent.putExtra("FILE_NAME", fileName);
startActivity(intent);

Then you can access that intent on next activity:

String fileName = getIntent().getStringExtra("fileName");
James
  • 1,843
  • 1
  • 8
  • 27
  • I have a method called openWithPhotoUri which get the activity and Uri and its what I have in my on click listener for the title bar. And I want to see how I can use that method without getting a null value exception – user10171817 Aug 17 '18 at 08:39