1、文件访问权限的改变,权限限制更加严格,需要手动赋予app的文件访问权限
AndroidManifest.xml
<!--写入SD卡的权限:如果你希望保存相机拍照后的照片-->
<!--<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
<!--读取SD卡的权限:打开相册选取图片所必须的权限-->
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
WelcomeActivity.java
public void manageExternalStorage() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
boolean isExternal = Environment.isExternalStorageManager();
Log.e("MyApplication", "android.os.Build.VERSION.SDK_INT:" + android.os.Build.VERSION.SDK_INT);
Log.e("MyApplication", "isExternal:" + isExternal);
if (!isExternal) {
DialogUtil.showConfirmDialog(
this,
"\"" + Constants.APP_NAME + "\"需要手动允许以下权限,您是否允许?", // title
"存储\n修改或删除存储卡的内容\n读取存储卡的内容", //content
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// 创建一个Intent指向系统的特定设置页面
Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
// 检查是否存在处理该Intent的应用
if (intent.resolveActivity(getPackageManager()) != null) {
// 如果存在,则启动该Activity
startActivityForResult(intent, REQUEST_CODE_PERMISSION_MANAGE_EXTERNAL);
} else {
// 如果不存在,可以引导用户到应用的设置页面
Intent appSettingsIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
appSettingsIntent.setData(uri);
startActivityForResult(appSettingsIntent, REQUEST_CODE_PERMISSION_MANAGE_EXTERNAL);
}
}
});
}else{
WelcomeActivity.this.startActivity(new Intent(WelcomeActivity.this, NectarLauncher.class));
WelcomeActivity.this.finish();
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==REQUEST_CODE_PERMISSION_MANAGE_EXTERNAL){
restartApp();
}
}
public void restartApp() {
Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
ComponentName componentName = intent.getComponent();
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
startActivity(mainIntent);
Runtime.getRuntime().exit(0);
}
2、关于定位权限 ACCESS_BACKGROUND_LOCATION:
targetSdk 小于29时,该权限需要申请这个:"android.permission.ACCESS_BACKGROUND_LOCATION"
Android14兼容需要将targetSdk升到34,所以权限由android.permission.ACCESS_BACKGROUND_LOCATION改
为"Manifest.permission.ACCESS_BACKGROUND_LOCATION"
如果不进行以上修改,会导致与其共同申请的权限不自动弹窗提示。
3、 targetSdk升34
compileSdk升到25以上
jdk升到17
build-tool升到com.android.tools.build:gradle:8.2.2
gradle升到https://services.gradle.org/distributions/gradle-8.2-bin.zip
基本可以保证编译不报错