Skip to content

Commit

Permalink
#feature: After the photo is taken, notify the system to update the m…
Browse files Browse the repository at this point in the history
…edia library. 拍照后通知系统扫描更新媒体库,解决目前拍照后在相册里找不到的问题。 (zhihu#511)

* #feature: After the photo is taken, notify the system to update the media library

* checkStyle: #feature: After the photo is taken, notify the system to update the media library

* Delete meaningless code

Delete meaningless code
  • Loading branch information
SherlockGougou authored and REBOOTERS committed Sep 11, 2019
1 parent 3ddaf23 commit 8de3344
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.zhihu.matisse.internal.utils;

import android.content.Context;
import android.media.MediaScannerConnection;
import android.net.Uri;

/**
* @author 工藤
* @email gougou@16fan.com
* create at 2018年10月23日12:17:59
* description:媒体扫描
*/
public class SingleMediaScanner implements MediaScannerConnection.MediaScannerConnectionClient {

private MediaScannerConnection mMsc;
private String mPath;
private ScanListener mListener;

public interface ScanListener {

/**
* scan finish
*/
void onScanFinish();
}

public SingleMediaScanner(Context context, String mPath, ScanListener mListener) {
this.mPath = mPath;
this.mListener = mListener;
this.mMsc = new MediaScannerConnection(context, this);
this.mMsc.connect();
}

@Override public void onMediaScannerConnected() {
mMsc.scanFile(mPath, null);
}

@Override public void onScanCompleted(String mPath, Uri mUri) {
mMsc.disconnect();
if (mListener != null) {
mListener.onScanFinish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.zhihu.matisse.internal.utils.PathUtils;
import com.zhihu.matisse.internal.utils.PhotoMetadataUtils;

import com.zhihu.matisse.internal.utils.SingleMediaScanner;
import java.util.ArrayList;

/**
Expand Down Expand Up @@ -234,6 +235,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
MatisseActivity.this.revokeUriPermission(contentUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);

new SingleMediaScanner(this.getApplicationContext(), path, new SingleMediaScanner.ScanListener() {
@Override public void onScanFinish() {
Log.i("SingleMediaScanner", "scan finish!");
}
});
finish();
}
}
Expand Down

0 comments on commit 8de3344

Please sign in to comment.