Skip to content

Commit

Permalink
修改头像裁剪目录,适配Android11
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueOcean1998 committed Apr 1, 2021
1 parent 92c6c70 commit 5653aba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode Integer.valueOf(getDate())
versionName "3.0.5"
versionName "3.0.6"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/cn/zerokirby/note/userutil/IconUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
Expand Down Expand Up @@ -69,17 +70,19 @@ public void handleImage(Intent data) {//处理接收到的图片
}

private void startPhotoZoom(Uri uri) {//图片缩放
File cropPhoto = new File(activity.getExternalCacheDir(), "crop.jpg");//创建临时文件
//创建临时文件,Android11后必须使用公共目录
File cropImagePath = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "ProgressNote");
if (!cropImagePath.exists()) cropImagePath.mkdir();
File cropImageFile = new File(cropImagePath, "crop_image.png");
if (cropImageFile.exists()) cropImageFile.delete();
try {
if (cropPhoto.exists()) {//如果临时文件存在则删除,否则新建
cropPhoto.delete();
}
cropPhoto.createNewFile();
cropImageFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}

cropImageUri = Uri.fromFile(cropPhoto);//获取裁剪图片的地址
cropImageUri = Uri.fromFile(cropImageFile);//获取裁剪图片的地址
Intent intent = new Intent("com.android.camera.action.CROP");//设置intent类型为裁剪图片
intent.setDataAndType(uri, "image/*");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Expand Down

0 comments on commit 5653aba

Please sign in to comment.