Skip to content

Commit

Permalink
1.回滚 PermissionUtils 代码
Browse files Browse the repository at this point in the history
Former-commit-id: 6cfe31a
Former-commit-id: c46194e
  • Loading branch information
Ttt committed Sep 30, 2020
1 parent de84f7b commit d95eec8
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.PermissionChecker;

import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -155,7 +154,7 @@ public void request(final Activity activity, final int requestCode) {
if (checkPermissions(activity) == 1) {
// 如果 SDK 版本大于 23 才请求
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
sInstance = new WeakReference<>(this);
sInstance = this;
// 请求权限
String[] permissions = mPermissionsRequestLists.toArray(new String[mPermissionsRequestLists.size()]);
// 判断请求方式
Expand Down Expand Up @@ -199,7 +198,7 @@ public interface PermissionCallBack {
// ================

// 内部持有对象
private static WeakReference<PermissionUtils> sInstance;
private static PermissionUtils sInstance;

/**
* detail: 请求权限 Activity
Expand All @@ -225,10 +224,9 @@ protected static void start(final Context context) {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (sInstance != null && sInstance.get() != null) { // 请求权限
int size = sInstance.get().mPermissionsRequestLists.size();
requestPermissions(sInstance.get().mPermissionsRequestLists.toArray(new String[size]), 1);
}
// 请求权限
int size = sInstance.mPermissionsRequestLists.size();
requestPermissions(sInstance.mPermissionsRequestLists.toArray(new String[size]), 1);
}

/**
Expand All @@ -239,9 +237,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (sInstance != null && sInstance.get() != null) { // 处理回调
sInstance.get().onRequestPermissionsResultCommon(this);
}
sInstance.onRequestPermissionsResultCommon(this); // 处理回调
finish(); // 关闭当前页面
}
}
Expand All @@ -264,8 +260,8 @@ private void onRequestPermissionsResultCommon(final Activity activity) {
* @param activity {@link Activity}
*/
public static void onRequestPermissionsResult(final Activity activity) {
if (activity != null && sInstance != null && sInstance.get() != null) { // 触发回调
sInstance.get().onRequestPermissionsResultCommon(activity);
if (activity != null && sInstance != null) { // 触发回调
sInstance.onRequestPermissionsResultCommon(activity);
}
}

Expand Down

0 comments on commit d95eec8

Please sign in to comment.