Commit f709fbc7 by 郭倩芳

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

parent 63307c87
...@@ -610,7 +610,7 @@ public abstract class SobotBaseActivity extends FragmentActivity { ...@@ -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,没有权限,尝试获取 * @return true, 已经获取权限;false,没有权限,尝试获取
*/ */
protected boolean checkStoragePermission(int checkType) { protected boolean checkStoragePermission(int checkType) {
...@@ -619,19 +619,9 @@ public abstract class SobotBaseActivity extends FragmentActivity { ...@@ -619,19 +619,9 @@ public abstract class SobotBaseActivity extends FragmentActivity {
//如果是升级Android13之后新装的应用,并且targetSDK大于等于33,则申请READ_EXTERNAL_STORAGE权限时会自动拒绝。 //如果是升级Android13之后新装的应用,并且targetSDK大于等于33,则申请READ_EXTERNAL_STORAGE权限时会自动拒绝。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (checkType == 0) { if (checkType == 0) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES) return true;
!= PackageManager.PERMISSION_GRANTED) {
//申请图片权限
this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_IMAGES}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
} else if (checkType == 1) { } else if (checkType == 1) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO) return true;
!= PackageManager.PERMISSION_GRANTED) {
//申请视频权限
this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_VIDEO}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
} else if (checkType == 2) { } else if (checkType == 2) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO) if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
...@@ -677,15 +667,9 @@ public abstract class SobotBaseActivity extends FragmentActivity { ...@@ -677,15 +667,9 @@ public abstract class SobotBaseActivity extends FragmentActivity {
protected boolean isHasStoragePermission(int checkPermissionType) { protected boolean isHasStoragePermission(int checkPermissionType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (checkPermissionType == 0) { if (checkPermissionType == 0) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES) return true;
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
} else if (checkPermissionType == 1) { } else if (checkPermissionType == 1) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO) return true;
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
} else if (checkPermissionType == 2) { } else if (checkPermissionType == 2) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO) if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
......
...@@ -20,11 +20,13 @@ public final class RomUtils { ...@@ -20,11 +20,13 @@ public final class RomUtils {
private static final String VIVO = "vivo"; private static final String VIVO = "vivo";
private static final String XIAOMI = "xiaomi"; private static final String XIAOMI = "xiaomi";
private static final String OPPO = "oppo"; 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_HUAWEI = "ro.build.version.emui";
private static final String VERSION_PROPERTY_VIVO = "ro.vivo.os.build.display.id"; 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_XIAOMI = "ro.build.version.incremental";
private static final String VERSION_PROPERTY_OPPO = "ro.build.version.opporom"; 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 final String UNKNOWN = "unknown";
private static RomInfo bean = null; private static RomInfo bean = null;
...@@ -68,6 +70,9 @@ public final class RomUtils { ...@@ -68,6 +70,9 @@ public final class RomUtils {
public static boolean isOppo() { public static boolean isOppo() {
return OPPO.equals(getRomInfo().name); return OPPO.equals(getRomInfo().name);
} }
public static boolean isOnePlus() {
return OnePlus.equals(getRomInfo().name);
}
/** /**
* Return the rom's information. * Return the rom's information.
...@@ -107,6 +112,13 @@ public final class RomUtils { ...@@ -107,6 +112,13 @@ public final class RomUtils {
} else { } else {
bean.name = manufacturer; 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(""); bean.version = getRomVersion("");
return bean; return bean;
} }
......
...@@ -15,6 +15,7 @@ import androidx.core.content.FileProvider; ...@@ -15,6 +15,7 @@ import androidx.core.content.FileProvider;
import com.sobot.utils.SobotIOUtils; import com.sobot.utils.SobotIOUtils;
import com.sobot.widget.ui.SobotBaseConstant; import com.sobot.widget.ui.SobotBaseConstant;
import com.sobot.widget.ui.notchlib.utils.RomUtils;
import com.sobot.widget.ui.toast.SobotToastUtil; import com.sobot.widget.ui.toast.SobotToastUtil;
import java.io.File; import java.io.File;
...@@ -41,12 +42,16 @@ public class SobotWidgetUtils { ...@@ -41,12 +42,16 @@ public class SobotWidgetUtils {
return; return;
} }
Intent intent; Intent intent;
if (Build.VERSION.SDK_INT < 19) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent = new Intent(Intent.ACTION_GET_CONTENT); intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
intent.setType("image/*"); 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, 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 { try {
if (childFragment != null) { if (childFragment != null) {
...@@ -89,9 +94,12 @@ public class SobotWidgetUtils { ...@@ -89,9 +94,12 @@ public class SobotWidgetUtils {
return; return;
} }
Intent intent; 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 = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*"); intent.setType("video/*");
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent = new Intent(Intent.ACTION_PICK_ACTIVITY);
intent.setType("video/*");
} else { } else {
intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI); intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
intent.setDataAndType(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "video/*"); 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