Commit f709fbc7 by 郭倩芳

Android 14 选择图片、视频的权限

parent 63307c87
......@@ -610,7 +610,7 @@ public abstract class SobotBaseActivity extends FragmentActivity {
/**
* 检查存储权限
*
* @param checkType 0:图片权限 1:视频权限,2:音频权限,3,所有细分的权限, android 13 使用 4:相册权限,读取相册图片和视频
* @param checkType 0:图片权限 1:视频权限,2:音频权限,3,所有细分的权限, android 13 使用 4:图片和视频权限,读取相册图片和视频
* @return true, 已经获取权限;false,没有权限,尝试获取
*/
protected boolean checkStoragePermission(int checkType) {
......@@ -619,19 +619,9 @@ public abstract class SobotBaseActivity extends FragmentActivity {
//如果是升级Android13之后新装的应用,并且targetSDK大于等于33,则申请READ_EXTERNAL_STORAGE权限时会自动拒绝。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (checkType == 0) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES)
!= PackageManager.PERMISSION_GRANTED) {
//申请图片权限
this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_IMAGES}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
return true;
} else if (checkType == 1) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO)
!= PackageManager.PERMISSION_GRANTED) {
//申请视频权限
this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_VIDEO}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
return true;
} else if (checkType == 2) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
......@@ -677,15 +667,9 @@ public abstract class SobotBaseActivity extends FragmentActivity {
protected boolean isHasStoragePermission(int checkPermissionType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (checkPermissionType == 0) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
return true;
} else if (checkPermissionType == 1) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
return true;
} else if (checkPermissionType == 2) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
......
......@@ -20,11 +20,13 @@ public final class RomUtils {
private static final String VIVO = "vivo";
private static final String XIAOMI = "xiaomi";
private static final String OPPO = "oppo";
private static final String OnePlus = "oneplus";
private static final String VERSION_PROPERTY_HUAWEI = "ro.build.version.emui";
private static final String VERSION_PROPERTY_VIVO = "ro.vivo.os.build.display.id";
private static final String VERSION_PROPERTY_XIAOMI = "ro.build.version.incremental";
private static final String VERSION_PROPERTY_OPPO = "ro.build.version.opporom";
private static final String VERSION_PROPERTY_ONEPLUS = "ro.build.version.opporom";
private static final String UNKNOWN = "unknown";
private static RomInfo bean = null;
......@@ -68,6 +70,9 @@ public final class RomUtils {
public static boolean isOppo() {
return OPPO.equals(getRomInfo().name);
}
public static boolean isOnePlus() {
return OnePlus.equals(getRomInfo().name);
}
/**
* Return the rom's information.
......@@ -107,6 +112,13 @@ public final class RomUtils {
} else {
bean.name = manufacturer;
}
if (isRightRom(brand, manufacturer, OnePlus)) {
bean.name = OnePlus;
bean.version = getRomVersion(VERSION_PROPERTY_ONEPLUS);
return bean;
} else {
bean.name = manufacturer;
}
bean.version = getRomVersion("");
return bean;
}
......
......@@ -15,6 +15,7 @@ import androidx.core.content.FileProvider;
import com.sobot.utils.SobotIOUtils;
import com.sobot.widget.ui.SobotBaseConstant;
import com.sobot.widget.ui.notchlib.utils.RomUtils;
import com.sobot.widget.ui.toast.SobotToastUtil;
import java.io.File;
......@@ -41,12 +42,16 @@ public class SobotWidgetUtils {
return;
}
Intent intent;
if (Build.VERSION.SDK_INT < 19) {
intent = new Intent(Intent.ACTION_GET_CONTENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
intent.setType("image/*");
} else {
// intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, 1);//设置获取最大图片数量
}else if(Build.VERSION.SDK_INT >= 19){
intent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}else{
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
}
try {
if (childFragment != null) {
......@@ -89,9 +94,12 @@ public class SobotWidgetUtils {
return;
}
Intent intent;
if (Build.VERSION.SDK_INT < 19) {
if (Build.VERSION.SDK_INT < 19 || RomUtils.isOppo() || RomUtils.isOnePlus()) {
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*");
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent = new Intent(Intent.ACTION_PICK_ACTIVITY);
intent.setType("video/*");
} else {
intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
intent.setDataAndType(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "video/*");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment