diff --git a/agentweb-core/src/main/java/com/just/agentweb/AgentWebPermissions.java b/agentweb-core/src/main/java/com/just/agentweb/AgentWebPermissions.java index fd5be564..5aef0301 100644 --- a/agentweb-core/src/main/java/com/just/agentweb/AgentWebPermissions.java +++ b/agentweb-core/src/main/java/com/just/agentweb/AgentWebPermissions.java @@ -25,29 +25,47 @@ * @since 1.0.0 */ public class AgentWebPermissions { - public static final String[] CAMERA; - public static final String[] LOCATION; - public static final String[] STORAGE; + public static String[] CAMERA; + public static String[] LOCATION; + public static String[] MEDIA; public static final String ACTION_CAMERA = "Camera"; public static final String ACTION_LOCATION = "Location"; - public static final String ACTION_STORAGE = "Storage"; + public static final String ACTION_MEDIA = "Media"; + static { CAMERA = new String[]{ Manifest.permission.CAMERA}; + LOCATION = new String[]{ Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) { - STORAGE = new String[]{ - Manifest.permission.READ_MEDIA_IMAGES, + MEDIA = new String[]{ Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_AUDIO, + Manifest.permission.READ_MEDIA_IMAGES, }; } else { - STORAGE = new String[]{ + MEDIA = new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE}; + Manifest.permission.WRITE_EXTERNAL_STORAGE + }; + } + } + + private static void emptyMediaPermission() { + MEDIA = new String[]{}; + } + + private static void emptyCameraPermission() { + CAMERA = new String[]{}; + } + + public static void dontAskUnnecessaryPermissions() { + if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { + emptyMediaPermission(); + emptyCameraPermission(); } } } diff --git a/agentweb-core/src/main/java/com/just/agentweb/AgentWebUtils.java b/agentweb-core/src/main/java/com/just/agentweb/AgentWebUtils.java index 1d5ea0c7..7a2eb658 100755 --- a/agentweb-core/src/main/java/com/just/agentweb/AgentWebUtils.java +++ b/agentweb-core/src/main/java/com/just/agentweb/AgentWebUtils.java @@ -75,6 +75,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; @@ -767,7 +768,7 @@ public static boolean hasPermission(@NonNull Context context, @NonNull List getDeniedPermissions(Activity activity, String[] permissions) { if (permissions == null || permissions.length == 0) { - return null; + return Collections.EMPTY_LIST; } List deniedPermissions = new ArrayList<>(permissions.length); for (int i = 0; i < permissions.length; i++) { diff --git a/agentweb-core/src/main/java/com/just/agentweb/DefaultDownloadImpl.java b/agentweb-core/src/main/java/com/just/agentweb/DefaultDownloadImpl.java index 49781339..59305c26 100644 --- a/agentweb-core/src/main/java/com/just/agentweb/DefaultDownloadImpl.java +++ b/agentweb-core/src/main/java/com/just/agentweb/DefaultDownloadImpl.java @@ -19,8 +19,6 @@ import android.app.Activity; import android.content.Context; import android.net.Uri; -import android.os.Build; -import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -32,9 +30,6 @@ import com.download.library.ResourceRequest; import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.concurrent.ConcurrentHashMap; import androidx.annotation.NonNull; @@ -108,7 +103,7 @@ protected void onDownloadStartInternal(String url, String userAgent, String cont return; } if (null != this.mPermissionListener) { - if (this.mPermissionListener.intercept(url, AgentWebPermissions.STORAGE, "download")) { + if (this.mPermissionListener.intercept(url, new String[]{}, "download")) { return; } } diff --git a/agentweb-filechooser/src/main/AndroidManifest.xml b/agentweb-filechooser/src/main/AndroidManifest.xml index 94cbbcfc..1c00a804 100644 --- a/agentweb-filechooser/src/main/AndroidManifest.xml +++ b/agentweb-filechooser/src/main/AndroidManifest.xml @@ -1 +1,8 @@ - + + + + + + + + diff --git a/agentweb-filechooser/src/main/java/com/just/agentweb/filechooser/FileChooser.java b/agentweb-filechooser/src/main/java/com/just/agentweb/filechooser/FileChooser.java index 2c862ab8..a716444d 100644 --- a/agentweb-filechooser/src/main/java/com/just/agentweb/filechooser/FileChooser.java +++ b/agentweb-filechooser/src/main/java/com/just/agentweb/filechooser/FileChooser.java @@ -176,10 +176,10 @@ public void run() { private void fileChooser() { List permission = null; - if (AgentWebUtils.getDeniedPermissions(mActivity, AgentWebPermissions.STORAGE).isEmpty()) { - touchOffFileChooserAction(); + if (AgentWebUtils.getDeniedPermissions(mActivity, AgentWebPermissions.MEDIA).isEmpty()) { + chooserAction(); } else { - Action mAction = Action.createPermissionsAction(AgentWebPermissions.STORAGE); + Action mAction = Action.createPermissionsAction(AgentWebPermissions.MEDIA); mAction.setFromIntention(FROM_INTENTION_CODE >> 2); mAction.setPermissionListener(mPermissionListener); AgentActionFragment.start(mActivity, mAction); @@ -188,7 +188,7 @@ private void fileChooser() { } - private void touchOffFileChooserAction() { + private void chooserAction() { Action mAction = new Action(); mAction.setAction(Action.ACTION_FILE); mAction.setChooserListener(getChooserListener()); @@ -270,12 +270,12 @@ private void openFileChooserInternal() { } } if (!needCamera && !needVideo) { - touchOffFileChooserAction(); + chooserAction(); return; } } if (!TextUtils.isEmpty(this.mAcceptType) && !this.mAcceptType.contains("*/") && !this.mAcceptType.contains("image/")) { - touchOffFileChooserAction(); + chooserAction(); return; } @@ -314,7 +314,6 @@ public boolean handleMessage(Message msg) { private void onCameraAction() { - if (mActivity == null) { return; } @@ -324,9 +323,7 @@ private void onCameraAction() { cancel(); return; } - } - Action mAction = new Action(); List deniedPermissions = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !(deniedPermissions = checkNeedPermission()).isEmpty()) { @@ -348,8 +345,8 @@ private List checkNeedPermission() { if (!AgentWebUtils.hasPermission(mActivity, AgentWebPermissions.CAMERA)) { deniedPermissions.add(AgentWebPermissions.CAMERA[0]); } - if (!AgentWebUtils.hasPermission(mActivity, AgentWebPermissions.STORAGE)) { - deniedPermissions.addAll(Arrays.asList(AgentWebPermissions.STORAGE)); + if (!AgentWebUtils.hasPermission(mActivity, AgentWebPermissions.MEDIA)) { + deniedPermissions.addAll(Arrays.asList(AgentWebPermissions.MEDIA)); } return deniedPermissions; } @@ -380,7 +377,7 @@ public void onRequestPermissionsResult(@NonNull String[] permissions, @NonNull i private void permissionResult(boolean grant, int fromIntention) { if (fromIntention == FROM_INTENTION_CODE >> 2) { if (grant) { - touchOffFileChooserAction(); + chooserAction(); } else { cancel(); @@ -388,8 +385,8 @@ private void permissionResult(boolean grant, int fromIntention) { mAgentWebUIController .get() .onPermissionsDeny( - AgentWebPermissions.STORAGE, - AgentWebPermissions.ACTION_STORAGE, + AgentWebPermissions.MEDIA, + AgentWebPermissions.ACTION_MEDIA, "Open file chooser"); } } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index d81e5451..ffe6c444 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,12 +1,18 @@ + + + + + + + - - - - diff --git a/sample/src/main/java/com/just/agentweb/sample/activity/CommonActivity.java b/sample/src/main/java/com/just/agentweb/sample/activity/CommonActivity.java index c2391b3c..50bcde01 100644 --- a/sample/src/main/java/com/just/agentweb/sample/activity/CommonActivity.java +++ b/sample/src/main/java/com/just/agentweb/sample/activity/CommonActivity.java @@ -76,15 +76,12 @@ private void openFragment(int key) { /*Fragment 使用AgenWeb*/ case FLAG_GUIDE_DICTIONARY_USE_IN_FRAGMENT: //项目中请使用常量代替0 , 代码可读性更高 - ft.add(R.id.container_framelayout, mAgentWebFragment = AgentWebFragment.getInstance(mBundle = new Bundle()), AgentWebFragment.class.getName()); - mBundle.putString(AgentWebFragment.URL_KEY, "http://cw.gzyunjuchuang.com/"); - break; - /*下载文件*/ + /*下载文件*/ case FLAG_GUIDE_DICTIONARY_FILE_DOWNLOAD: ft.add(R.id.container_framelayout, mAgentWebFragment = AgentWebFragment.getInstance(mBundle = new Bundle()), AgentWebFragment.class.getName()); mBundle.putString(AgentWebFragment.URL_KEY, "http://android.myapp.com/"); break; - /*input标签上传文件*/ + /*input标签上传文件*/ case FLAG_GUIDE_DICTIONARY_INPUT_TAG_PROBLEM: ft.add(R.id.container_framelayout, mAgentWebFragment = AgentWebFragment.getInstance(mBundle = new Bundle()), AgentWebFragment.class.getName()); mBundle.putString(AgentWebFragment.URL_KEY, "file:///android_asset/upload_file/uploadfile.html"); @@ -118,7 +115,7 @@ private void openFragment(int key) { /*豌豆荚*/ case FLAG_GUIDE_DICTIONARY_CUSTOM_WEBVIEW_SETTINGS: ft.add(R.id.container_framelayout, mAgentWebFragment = CustomSettingsFragment.getInstance(mBundle = new Bundle()), CustomSettingsFragment.class.getName()); - mBundle.putString(AgentWebFragment.URL_KEY, "http://www.wandoujia.com/apps"); + mBundle.putString(AgentWebFragment.URL_KEY, "https://m.wandoujia.com/"); break; /*短信*/ diff --git a/sample/src/main/res/xml/network_security_config.xml b/sample/src/main/res/xml/network_security_config.xml index 6f168a83..238fb198 100644 --- a/sample/src/main/res/xml/network_security_config.xml +++ b/sample/src/main/res/xml/network_security_config.xml @@ -3,7 +3,6 @@ - \ No newline at end of file