From d95eec8b79a2f66a36192eb5d80e2019a8666d87 Mon Sep 17 00:00:00 2001 From: Ttt <13798405957@163.com> Date: Wed, 30 Sep 2020 10:09:01 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=9B=9E=E6=BB=9A=20PermissionUtils=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 6cfe31af98eaf844abfae28482e76942bf297e22 Former-commit-id: c46194e9920c1368f83d77e625d51096f5ce4d67 --- .../utils/app/permission/PermissionUtils.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/DevApp/src/main/java/dev/utils/app/permission/PermissionUtils.java b/lib/DevApp/src/main/java/dev/utils/app/permission/PermissionUtils.java index 12c926cf88..ada89c3e40 100644 --- a/lib/DevApp/src/main/java/dev/utils/app/permission/PermissionUtils.java +++ b/lib/DevApp/src/main/java/dev/utils/app/permission/PermissionUtils.java @@ -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; @@ -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()]); // 判断请求方式 @@ -199,7 +198,7 @@ public interface PermissionCallBack { // ================ // 内部持有对象 - private static WeakReference sInstance; + private static PermissionUtils sInstance; /** * detail: 请求权限 Activity @@ -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); } /** @@ -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(); // 关闭当前页面 } } @@ -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); } }