How can I save my bitmap correctly for second time?

微笑、不失礼 提交于 2019-12-01 04:26:43

Finally I solved my problem like this:

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, getImageUri(context,bitmap_));
shareIntent.setType("image/jpeg");
startActivityForResult(Intent.createChooser(shareIntent, getResources().getText(R.string.title_share)),whtsapp_result);

v

public Uri getImageUri(Context inContext, Bitmap inImage) {
          ByteArrayOutputStream bytes = new ByteArrayOutputStream();
          inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
          String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "TitleC1", null);
          return Uri.parse(path);
        }

This is just a guess, but since you save a new image (with the old name, or another, that’s not relevant) you should fire a media scan to that path so that the media provider is updated with new content.

See here:

MediaScannerConnection.scanFile(context, new String[]{imagePath}, null, null);

Or even better, wait for the scan to be completed:

MediaScannerConnection.scanFile(context, new String[]{imagePath}, null, new OnScanCompletedListener() {
    @Override
    void onScanCompleted(String path, Uri uri) {
        // Send your intent now.
    }
});

In any case this should be called after the new file is saved. As I said, I have not tested and this is just a random guess.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!