Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完成Android14的READ_MEDIA_VISUAL_USER_SELECTED适配 #2779

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ static def releaseTime() {
}

android {
compileSdkVersion 33
compileSdk 34

defaultConfig {
applicationId "com.luck.pictureselector"
minSdkVersion 21
targetSdkVersion 33
minSdk 21
targetSdk 34
versionCode cfgs.versionCode
versionName cfgs.versionName
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED"/>


<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
2 changes: 0 additions & 2 deletions camerax/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 31
versionCode cfgs.versionCode
versionName cfgs.versionName

consumerProguardFiles "consumer-rules.pro"
}
Expand Down
3 changes: 0 additions & 3 deletions compress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ buildscript {

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode cfgs.versionCode
versionName cfgs.versionName
}
buildTypes {
release {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
8 changes: 3 additions & 5 deletions selector/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 30
compileSdk 34

defaultConfig {
minSdkVersion 19
targetSdkVersion 31
versionCode cfgs.versionCode
versionName cfgs.versionName
minSdk 19
targetSdk 34

vectorDrawables.useSupportLibrary = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected Context getAppContext() {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (mPermissionResultCallback != null) {
PermissionChecker.getInstance().onRequestPermissionsResult(grantResults, mPermissionResultCallback);
PermissionChecker.getInstance().onRequestPermissionsResult(getContext(),permissions,grantResults, mPermissionResultCallback);
mPermissionResultCallback = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ private void requestPermissions(Fragment fragment, List<String[]> permissionGrou
}
}

public void onRequestPermissionsResult(int[] grantResults, PermissionResultCallback action) {
if (PermissionUtil.isAllGranted(grantResults)) {
public void onRequestPermissionsResult(Context context,String[] permissions,int[] grantResults, PermissionResultCallback action) {
if (PermissionUtil.isAllGranted(context,permissions,grantResults)) {
action.onGranted();
} else {
action.onDenied();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import android.Manifest;
import android.content.Context;
import android.os.Build;
import android.util.Log;

import androidx.annotation.RequiresApi;

import com.luck.picture.lib.config.SelectMimeType;
import com.luck.picture.lib.utils.SdkVersionUtils;
Expand All @@ -13,9 +17,14 @@
*/
public class PermissionConfig {

public static final String READ_MEDIA_AUDIO = "android.permission.READ_MEDIA_AUDIO";
public static final String READ_MEDIA_IMAGES = "android.permission.READ_MEDIA_IMAGES";
public static final String READ_MEDIA_VIDEO = "android.permission.READ_MEDIA_VIDEO";
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
public static final String READ_MEDIA_AUDIO = Manifest.permission.READ_MEDIA_AUDIO;
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
public static final String READ_MEDIA_IMAGES = Manifest.permission.READ_MEDIA_IMAGES;
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
public static final String READ_MEDIA_VIDEO = Manifest.permission.READ_MEDIA_VIDEO;
@RequiresApi(api = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
public static final String READ_MEDIA_VISUAL_USER_SELECTED = Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED;
public static final String READ_EXTERNAL_STORAGE = Manifest.permission.READ_EXTERNAL_STORAGE;
public static final String WRITE_EXTERNAL_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE;
/**
Expand All @@ -32,24 +41,55 @@ public class PermissionConfig {
* 获取外部读取权限
*/
public static String[] getReadPermissionArray(Context context, int chooseMode) {
if (SdkVersionUtils.isTIRAMISU()) {
if (SdkVersionUtils.isUPSIDE_DOWN_CAKE()){
int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
if (chooseMode == SelectMimeType.ofImage()) {
if (targetSdkVersion >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE){
return new String[]{READ_MEDIA_VISUAL_USER_SELECTED,READ_MEDIA_IMAGES};
}else if (targetSdkVersion == Build.VERSION_CODES.TIRAMISU){
return new String[]{READ_MEDIA_IMAGES};
}else {
return new String[]{READ_EXTERNAL_STORAGE};
}
} else if (chooseMode == SelectMimeType.ofVideo()) {
if (targetSdkVersion >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE){
return new String[]{READ_MEDIA_VISUAL_USER_SELECTED,READ_MEDIA_VIDEO};
}else if (targetSdkVersion == Build.VERSION_CODES.TIRAMISU){
return new String[]{READ_MEDIA_VIDEO};
}else {
return new String[]{READ_EXTERNAL_STORAGE};
}
} else if (chooseMode == SelectMimeType.ofAudio()) {
return targetSdkVersion >= Build.VERSION_CODES.TIRAMISU
? new String[]{READ_MEDIA_AUDIO}
: new String[]{READ_EXTERNAL_STORAGE};
} else {
if (targetSdkVersion >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE){
return new String[]{READ_MEDIA_VISUAL_USER_SELECTED,READ_MEDIA_IMAGES, READ_MEDIA_VIDEO};
}else if (targetSdkVersion == Build.VERSION_CODES.TIRAMISU){
return new String[]{READ_MEDIA_IMAGES, READ_MEDIA_VIDEO};
}else {
return new String[]{READ_EXTERNAL_STORAGE};
}
}
}else if (SdkVersionUtils.isTIRAMISU()) {
int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
if (chooseMode == SelectMimeType.ofImage()) {
return targetSdkVersion >= SdkVersionUtils.TIRAMISU
return targetSdkVersion >= Build.VERSION_CODES.TIRAMISU
? new String[]{READ_MEDIA_IMAGES}
: new String[]{READ_MEDIA_IMAGES, READ_EXTERNAL_STORAGE};
: new String[]{READ_EXTERNAL_STORAGE};
} else if (chooseMode == SelectMimeType.ofVideo()) {
return targetSdkVersion >= SdkVersionUtils.TIRAMISU
return targetSdkVersion >= Build.VERSION_CODES.TIRAMISU
? new String[]{READ_MEDIA_VIDEO}
: new String[]{READ_MEDIA_VIDEO, READ_EXTERNAL_STORAGE};
: new String[]{READ_EXTERNAL_STORAGE};
} else if (chooseMode == SelectMimeType.ofAudio()) {
return targetSdkVersion >= SdkVersionUtils.TIRAMISU
return targetSdkVersion >= Build.VERSION_CODES.TIRAMISU
? new String[]{READ_MEDIA_AUDIO}
: new String[]{READ_MEDIA_AUDIO, READ_EXTERNAL_STORAGE};
: new String[]{READ_EXTERNAL_STORAGE};
} else {
return targetSdkVersion >= SdkVersionUtils.TIRAMISU
return targetSdkVersion >= Build.VERSION_CODES.TIRAMISU
? new String[]{READ_MEDIA_IMAGES, READ_MEDIA_VIDEO}
: new String[]{READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, READ_EXTERNAL_STORAGE};
: new String[]{READ_EXTERNAL_STORAGE};
}
}
return new String[]{READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Size;
Expand Down Expand Up @@ -47,11 +48,24 @@ public static boolean hasPermissions(@NonNull Context context, @Size(min = 1) @N
return true;
}

public static boolean isAllGranted(int[] grantResults) {
public static boolean isAllGranted(Context context,String[] permissions,int[] grantResults) {
boolean isAllGranted = true;
boolean skipPermissionReject = false;
int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
if (targetSdkVersion >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE){
if (ContextCompat.checkSelfPermission(context, PermissionConfig.READ_MEDIA_VISUAL_USER_SELECTED) == PackageManager.PERMISSION_GRANTED) {
skipPermissionReject = true;
}
}
if (grantResults.length > 0) {
for (int grant : grantResults) {
if (grant != PackageManager.PERMISSION_GRANTED) {
for (int i = 0; i<grantResults.length; i++){
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
if (skipPermissionReject){
if (permissions[i].equals(PermissionConfig.READ_MEDIA_IMAGES) ||
permissions[i].equals(PermissionConfig.READ_MEDIA_VIDEO)){
break;
}
}
isAllGranted = false;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
*/
public class SdkVersionUtils {

public static final int R = 30;

public static final int TIRAMISU = 33;

/**
* 判断是否是低于Android LOLLIPOP版本
*/
Expand Down Expand Up @@ -61,13 +57,20 @@ public static boolean isQ() {
* 判断是否是Android R版本
*/
public static boolean isR() {
return Build.VERSION.SDK_INT >= R;
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R;
}

/**
* 判断是否是Android TIRAMISU版本
*/
public static boolean isTIRAMISU() {
return Build.VERSION.SDK_INT >= TIRAMISU;
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
}

/**
* 判断是否是Android UPSIDE_DOWN_CAKE版本
*/
public static boolean isUPSIDE_DOWN_CAKE() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE;
}
}
3 changes: 0 additions & 3 deletions ucrop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 29
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode cfgs.versionCode
versionName cfgs.versionName
vectorDrawables.useSupportLibrary = true
}
buildTypes {
Expand Down