Skip to content

Commit

Permalink
修复media store compat 可能没有初始化的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhengyin committed Oct 26, 2022
1 parent e5bc3d8 commit d680534
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions matisse/src/main/java/com/zhihu/matisse/ui/MatisseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class MatisseActivity extends AppCompatActivity implements
private static final int REQUEST_CODE_CAPTURE = 24;
public static final String CHECK_STATE = "checkState";
private final AlbumCollection mAlbumCollection = new AlbumCollection();
@Nullable
private MediaStoreCompat mMediaStoreCompat;
private final SelectedItemCollection mSelectedCollection = new SelectedItemCollection(this);
private SelectionSpec mSpec;
Expand Down Expand Up @@ -170,8 +171,15 @@ protected void onSaveInstanceState(@NonNull Bundle outState) {
mSelectedCollection.onSaveInstanceState(outState);
mAlbumCollection.onSaveInstanceState(outState);
outState.putBoolean("checkState", mOriginalEnable);
Uri currentPhotoUri = mMediaStoreCompat.getCurrentPhotoUri();
String currentPhotoPath = mMediaStoreCompat.getCurrentPhotoPath();
MediaStoreCompat compat = this.mMediaStoreCompat;
if (compat != null) {
saveLastSelected(outState, compat);
}
}

private void saveLastSelected(@NonNull Bundle outState, @NonNull MediaStoreCompat compat) {
Uri currentPhotoUri = compat.getCurrentPhotoUri();
String currentPhotoPath = compat.getCurrentPhotoPath();
if (currentPhotoUri != null && currentPhotoPath != null) {
outState.putString("path", currentPhotoPath);
outState.putString("uri", currentPhotoUri.toString());
Expand Down

0 comments on commit d680534

Please sign in to comment.