浏览代码

修改权限申请展示

xbWang 2 月之前
父节点
当前提交
e4db20775b

二进制
app/debug/app-debug.apk


二进制
app/release/app-release.apk


二进制
app/release/hbc.apk → app/release/hba.apk


+ 0 - 1
app/release/hbc.apk.cache/code-version

@@ -1 +0,0 @@
-13:1.4.7:cc60397faac154890c9f2f4683bb70b6:d9dc9d03a74a99507881eea4e96185e3

二进制
app/release/hbc.apk.cache/names-map


+ 41 - 6
app/src/main/java/com/hbc/hbc/function/WebFragmentFunction.java

@@ -1,11 +1,9 @@
 package com.hbc.hbc.function;
 
-import android.Manifest;
 import android.animation.ValueAnimator;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.PackageManager;
 import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Bundle;
@@ -13,17 +11,22 @@ import android.view.View;
 import android.view.animation.LinearInterpolator;
 import android.webkit.JavascriptInterface;
 
-import androidx.core.app.ActivityCompat;
-import androidx.core.content.ContextCompat;
+import androidx.annotation.NonNull;
 import androidx.fragment.app.Fragment;
 
+import com.hbc.hbc.customView.NotificationMsgPopup;
 import com.hbc.hbc.utils.AliPayUtil;
 import com.hbc.hbc.utils.CameraUtils;
 import com.hbc.hbc.utils.QQShareUtils;
 import com.hbc.hbc.utils.WXShareUtils;
 import com.hbc.hbc.utils.WeChatPayUtils;
+import com.hjq.permissions.OnPermissionCallback;
+import com.hjq.permissions.Permission;
+import com.hjq.permissions.XXPermissions;
 import com.hjq.toast.Toaster;
 import com.lxj.xpopup.XPopup;
+import com.lxj.xpopup.core.BasePopupView;
+import com.lxj.xpopup.enums.PopupAnimation;
 import com.lxj.xpopup.interfaces.OnCancelListener;
 import com.lxj.xpopup.interfaces.OnConfirmListener;
 import com.hbc.hbc.R;
@@ -44,6 +47,7 @@ import org.json.JSONObject;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
 
 /**
  * @author Bei
@@ -54,6 +58,7 @@ public class WebFragmentFunction extends BaseFunction {
     private Context context;
     private Activity activity;
     private Fragment fragment;
+    static BasePopupView xPopup = null;
 
     private static final int SDK_PAY_FLAG = 1;
 
@@ -498,8 +503,38 @@ public class WebFragmentFunction extends BaseFunction {
         } catch (JSONException e) {
             throw new RuntimeException(e);
         }
-        MainActivity mainActivity = (MainActivity) context;
-        mainActivity.scanResultLauncher.launch(null);
+
+        if (!XXPermissions.isGranted(activity, Permission.CAMERA)) {
+            xPopup = new XPopup.Builder(activity)
+                    .isDestroyOnDismiss(true)
+                    .popupAnimation(PopupAnimation.TranslateFromTop)
+                    .asCustom(new NotificationMsgPopup(activity, "相机扫描二维码/条形码申请此权限"))
+                    .show();
+        }
+
+        XXPermissions.with(activity)
+                .permission(Permission.CAMERA)
+                .request(new OnPermissionCallback() {
+                    @Override
+                    public void onGranted(@NonNull List<String> permissions, boolean all) {
+                        if (null != xPopup) {
+                            xPopup.dismiss();
+                        }
+                        MainActivity mainActivity = (MainActivity) context;
+                        mainActivity.scanResultLauncher.launch(null);
+                    }
+
+                    @Override
+                    public void onDenied(@NonNull List<String> permissions, boolean never) {
+                        if (null != xPopup) {
+                            xPopup.dismiss();
+                        }
+                        if (never) {
+                            Toaster.show("拒绝授权,请手动添加APP应用相机权限");
+                        }
+                    }
+                });
+
     }
 
     @JavascriptInterface

+ 40 - 2
app/src/main/java/com/hbc/hbc/function/WebFunction.java

@@ -8,9 +8,11 @@ import android.os.Build;
 import android.os.Bundle;
 import android.webkit.JavascriptInterface;
 
+import androidx.annotation.NonNull;
 import androidx.appcompat.app.AppCompatActivity;
 
 import com.hbc.hbc.app.MainApplication;
+import com.hbc.hbc.customView.NotificationMsgPopup;
 import com.hbc.hbc.utils.AliPayUtil;
 import com.hbc.hbc.utils.CameraUtils;
 import com.hbc.hbc.utils.DownloadImg;
@@ -25,15 +27,20 @@ import com.hbc.hbc.R;
 import com.hbc.hbc.activity.MainActivity;
 import com.hbc.hbc.activity.PublicWebActivity;
 import com.hbc.hbc.activity.WebActivity;
+import com.hjq.permissions.OnPermissionCallback;
 import com.hjq.permissions.Permission;
 import com.hjq.permissions.XXPermissions;
 import com.hjq.toast.Toaster;
+import com.lxj.xpopup.XPopup;
+import com.lxj.xpopup.core.BasePopupView;
+import com.lxj.xpopup.enums.PopupAnimation;
 import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import java.io.IOException;
+import java.util.List;
 
 /**
  * @author Bei
@@ -43,6 +50,7 @@ public class WebFunction extends BaseFunction {
 
     private final Context context;
     private final AppCompatActivity activity;
+    static BasePopupView xPopup = null;
 
     public WebFunction(Context context, AppCompatActivity activity) {
         this.context = context;
@@ -608,8 +616,38 @@ public class WebFunction extends BaseFunction {
         } catch (JSONException e) {
             throw new RuntimeException(e);
         }
-        PublicWebActivity publicWebActivity = (PublicWebActivity) context;
-        publicWebActivity.scanResultLauncher.launch(null);
+
+        if (!XXPermissions.isGranted(activity, Permission.CAMERA)) {
+            xPopup = new XPopup.Builder(activity)
+                    .isDestroyOnDismiss(true)
+                    .popupAnimation(PopupAnimation.TranslateFromTop)
+                    .asCustom(new NotificationMsgPopup(activity, "相机扫描二维码/条形码申请此权限"))
+                    .show();
+        }
+
+        XXPermissions.with(activity)
+                .permission(Permission.CAMERA)
+                .request(new OnPermissionCallback() {
+                    @Override
+                    public void onGranted(@NonNull List<String> permissions, boolean all) {
+                        if (null != xPopup) {
+                            xPopup.dismiss();
+                        }
+                        PublicWebActivity publicWebActivity = (PublicWebActivity) context;
+                        publicWebActivity.scanResultLauncher.launch(null);
+                    }
+
+                    @Override
+                    public void onDenied(@NonNull List<String> permissions, boolean never) {
+                        if (null != xPopup) {
+                            xPopup.dismiss();
+                        }
+                        if (never) {
+                            Toaster.show("拒绝授权,请手动添加APP应用相机权限");
+                        }
+                    }
+                });
+
     }
 
     @JavascriptInterface