Bladeren bron

PDFTool(Android) - 优化CPDFDocumentFragment界面开启时,权限申请问题

liuxiaolong 10 maanden geleden
bovenliggende
commit
4e0ca76d40

BIN
ComPDFKit_Repo/compdfkit-ui/ComPDFKit-UI.aar


BIN
ComPDFKit_Repo/compdfkit/ComPDFKit.aar


+ 2 - 2
ComPDFKit_Tools/build.gradle

@@ -53,8 +53,8 @@ dependencies {
     api fileTree(include: ['*.jar'], dir: 'libs')
     api project(path:':ComPDFKit_Repo:compdfkit')
     api project(path:':ComPDFKit_Repo:compdfkit-ui')
-//    api 'com.compdf:compdfkit:1.11.0'
-//    api 'com.compdf:compdfkit-ui:1.11.0'
+//    api 'com.compdf:compdfkit:1.13.0'
+//    api 'com.compdf:compdfkit-ui:1.13.0'
     api 'com.github.bumptech.glide:glide:4.15.1'
     annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
     api 'androidx.documentfile:documentfile:1.0.1'

+ 9 - 2
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/pdf/CPDFDocumentFragment.java

@@ -17,6 +17,8 @@ import static com.compdfkit.tools.contenteditor.CEditToolbar.SELECT_AREA_TEXT;
 import android.Manifest;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.graphics.Paint;
 import android.net.Uri;
@@ -25,6 +27,7 @@ import android.os.Bundle;
 import android.os.Environment;
 import android.provider.Settings;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -52,6 +55,7 @@ import com.compdfkit.tools.common.contextmenu.CPDFContextMenuHelper;
 import com.compdfkit.tools.common.pdf.config.CPDFConfiguration;
 import com.compdfkit.tools.common.pdf.config.ToolbarConfig;
 import com.compdfkit.tools.common.utils.CFileUtils;
+import com.compdfkit.tools.common.utils.CLog;
 import com.compdfkit.tools.common.utils.CPermissionUtil;
 import com.compdfkit.tools.common.utils.CToastUtil;
 import com.compdfkit.tools.common.utils.activitycontracts.CSelectPDFDocumentResultContract;
@@ -91,6 +95,7 @@ import com.compdfkit.ui.reader.CPDFReaderView;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 
@@ -743,13 +748,15 @@ public class CPDFDocumentFragment extends CBasicPDFFragment {
             return;
         }
         if (Build.VERSION.SDK_INT >= CPermissionUtil.VERSION_TIRAMISU) {
-            requestManageStoragePermission.launch(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION));
+            if (CPermissionUtil.checkManifestPermission(getContext(), Manifest.permission.MANAGE_EXTERNAL_STORAGE)){
+                requestManageStoragePermission.launch(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION));
+            }
         } else if (Build.VERSION.SDK_INT >= CPermissionUtil.VERSION_R) {
             multiplePermissionResultLauncher.launch(STORAGE_PERMISSIONS, result -> {
                 if (CPermissionUtil.hasStoragePermissions(getContext())) {
                     initDocument(null);
                 } else {
-                    if (!Environment.isExternalStorageManager()) {
+                    if (!Environment.isExternalStorageManager() && CPermissionUtil.checkManifestPermission(getContext(), Manifest.permission.MANAGE_EXTERNAL_STORAGE)) {
                         requestManageStoragePermission.launch(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION));
                     }
                 }

+ 34 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/utils/CPermissionUtil.java

@@ -13,11 +13,13 @@ package com.compdfkit.tools.common.utils;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Environment;
 import android.provider.Settings;
+import android.util.Log;
 
 import androidx.core.app.ActivityCompat;
 import androidx.core.content.ContextCompat;
@@ -26,6 +28,10 @@ import androidx.fragment.app.FragmentManager;
 import com.compdfkit.tools.R;
 import com.compdfkit.tools.common.utils.dialog.CAlertDialog;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 public class CPermissionUtil {
 
     public static final int VERSION_TIRAMISU = 33;
@@ -105,4 +111,32 @@ public class CPermissionUtil {
         alertDialog.setCancelClickListener(v -> alertDialog.dismiss());
         alertDialog.show(fragmentManager, "permissionRequiredDialog");
     }
+
+    public static List<String> getManifestPermissions(Context context){
+        ArrayList<String> requestedPermissionsArrayList = new ArrayList<String>();
+        PackageManager pm = context.getPackageManager();
+        try {
+            PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
+            String[] requestedPermissions = null;
+            if (packageInfo != null) {
+                requestedPermissions = packageInfo.requestedPermissions;
+            }
+
+            if (requestedPermissions != null && requestedPermissions.length > 0) {
+                List<String> requestedPermissionsList = Arrays.asList(requestedPermissions);
+                requestedPermissionsArrayList.addAll(requestedPermissionsList);
+            }
+            return requestedPermissionsArrayList;
+        } catch (PackageManager.NameNotFoundException e) {
+            e.printStackTrace();
+        }
+        return requestedPermissionsArrayList;
+    }
+
+    public static boolean checkManifestPermission(Context context, String permission) {
+        List<String> manifestPermissions = getManifestPermissions(context);
+        return manifestPermissions.contains(permission);
+    }
+
+
 }

File diff suppressed because it is too large
+ 4 - 1
PDFViewer/src/main/AndroidManifest.xml


+ 1 - 1
compdfkit-tools-mavencentral.gradle

@@ -1,7 +1,7 @@
 apply plugin: 'maven-publish'
 apply plugin: 'signing'
 
-def PUBLISH_VERSION = '1.12.0'
+def PUBLISH_VERSION = '1.13.0-SNAPSHOT'
 def PUBLISH_GROUP_ID = 'com.compdf'
 def PUBLISH_ARTIFACT_ID = 'compdfkit-tools'
 

+ 1 - 1
config.gradle

@@ -6,7 +6,7 @@ ext {
             VERSIONCODE: 1007
     ]
     sdk = [
-            COMPDFKIT_SDK_VERSION : "1.12.0",
+            COMPDFKIT_SDK_VERSION : "1.13.0",
             COMPDFKIT_SDK_BUILD_TAG : "build_beta_1.12.0_e6d87965c_202401171610"
     ]
 }