Skip to content

Commit

Permalink
修复更新个人头像时,可能未授权问题
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Jul 16, 2023
1 parent 371cdc1 commit 85caf3d
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

package cn.wildfire.chat.kit.user;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -283,6 +286,28 @@ void showUserMessages() {
private static final int REQUEST_CODE_PICK_IMAGE = 100;

void portrait() {
String[] permissions;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
permissions = new String[]{
Manifest.permission.READ_MEDIA_IMAGES,
};
} else {
permissions = new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
};
}
Activity activity = getActivity();
if (activity == null) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (String permission : permissions) {
if (activity.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(permissions, 100);
return;
}
}
}
if (userInfo.uid.equals(userViewModel.getUserId())) {
updatePortrait();
} else {
Expand Down

0 comments on commit 85caf3d

Please sign in to comment.