沃创云 v1.0.2版本的 MD5 值为:75fd4b81bf3100e28225c876f02b8eb1

以下内容为反编译后的 TUriUtils.java 源代码,内容仅作参考


package com.sl.utakephoto.utils;

import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import androidx.core.content.FileProvider;
import com.sl.utakephoto.exception.TakeException;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class TUriUtils {
    public static Uri checkTakePhotoUri(Context context, Uri uri, String str) throws TakeException {
        if (uri == null) {
            return getTempSchemeContentUri(context, str);
        }
        if (!"file".equals(uri.getScheme())) {
            return uri;
        }
        if (Build.VERSION.SDK_INT >= 29) {
            if (Environment.isExternalStorageLegacy()) {
                Log.w(TConstant.TAG, "当前是Legacy View视图,兼容File方式访问");
                File file = new File(uri.getPath());
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                return getUriFromFile(context, file);
            }
            if (checkAppSpecific(uri, context)) {
                File file2 = new File(uri.getPath());
                if (!file2.getParentFile().exists()) {
                    file2.getParentFile().mkdirs();
                }
                return getUriFromFile(context, file2);
            }
            Log.w(TConstant.TAG, "当前存储空间视图模式是Filtered View,不能直接访问App-specific外的文件");
            throw new TakeException(12, "当前是Filtered View,不能直接访问App-specific外的文件,Environment.getExternalStorageDirectory()不能使用,请使用MediaStore或者使用getExternalFilesDirs、getExternalCacheDirs等,可查看 https://developer.android.google.cn/preview/privacy/scoped-storage");
        }
        File file3 = new File(uri.getPath());
        if (!file3.getParentFile().exists()) {
            file3.getParentFile().mkdirs();
        }
        if (Build.VERSION.SDK_INT >= 24) {
            return getUriFromFile(context, file3);
        }
        return Uri.fromFile(file3);
    }

    public static Uri checkCropUri(Context context, Uri uri, String str) throws TakeException {
        if (uri == null) {
            return getTempSchemeFileUri(context, str);
        }
        if (!"file".equals(uri.getScheme())) {
            return uri;
        }
        if (Build.VERSION.SDK_INT >= 29) {
            if (Environment.isExternalStorageLegacy()) {
                Log.w(TConstant.TAG, "当前是Legacy View视图,兼容File方式访问");
                File file = new File(uri.getPath());
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                return uri;
            }
            if (checkAppSpecific(uri, context)) {
                File file2 = new File(uri.getPath());
                if (!file2.getParentFile().exists()) {
                    file2.getParentFile().mkdirs();
                }
                return uri;
            }
            Log.w(TConstant.TAG, "当前存储空间视图模式是Filtered View,不能直接访问App-specific外的文件");
            throw new TakeException(12, "当前是Filtered View,不能直接访问App-specific外的文件,Environment.getExternalStorageDirectory()不能使用,请使用MediaStore或者使用getExternalFilesDirs、getExternalCacheDirs等,可查看 https://developer.android.google.cn/preview/privacy/scoped-storage");
        }
        File file3 = new File(uri.getPath());
        if (!file3.getParentFile().exists()) {
            file3.getParentFile().mkdirs();
        }
        return Uri.fromFile(file3);
    }

    private static boolean checkAppSpecific(Uri uri, Context context) {
        if (uri != null && uri.getPath() != null) {
            String path = uri.getPath();
            if ((context.getExternalMediaDirs().length != 0 && path.startsWith(context.getExternalMediaDirs()[0].getAbsolutePath())) || path.startsWith(context.getObbDir().getAbsolutePath()) || path.startsWith(context.getExternalCacheDir().getAbsolutePath()) || path.startsWith(context.getExternalFilesDir("").getAbsolutePath())) {
                return true;
            }
        }
        return false;
    }

    public static Uri getUriFromFile(Context context, File file) {
        return FileProvider.getUriForFile(context, TConstant.getFileProviderName(context), file);
    }

    public static Uri getTempSchemeContentUri(Context context, String str) {
        String format = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date());
        File externalFilesDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        StringBuilder sb = new StringBuilder();
        sb.append("/");
        sb.append(format);
        if (TextUtils.isEmpty(str)) {
            str = ".jpg";
        }
        sb.append(str);
        File file = new File(externalFilesDir, sb.toString());
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        if (Build.VERSION.SDK_INT >= 24) {
            return getUriFromFile(context, file);
        }
        return Uri.fromFile(file);
    }

    public static Uri getTempSchemeFileUri(Context context) {
        return getTempSchemeFileUri(context, null);
    }

    public static Uri getTempSchemeFileUri(Context context, String str) {
        String format = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date());
        File externalFilesDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        StringBuilder sb = new StringBuilder();
        sb.append("/");
        sb.append(format);
        if (TextUtils.isEmpty(str)) {
            str = ".jpg";
        }
        sb.append(str);
        File file = new File(externalFilesDir, sb.toString());
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        return Uri.fromFile(file);
    }

    public static Uri getTempSchemeUri(Context context) {
        if (Build.VERSION.SDK_INT >= 30) {
            return getTempSchemeUriR(context);
        }
        return getTempSchemeFileUri(context);
    }

    private static Uri getTempSchemeUriR(Context context) {
        String str = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date()) + "_CROP.jpg";
        File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + str);
        ContentValues contentValues = new ContentValues();
        contentValues.put("_data", file.getAbsolutePath());
        contentValues.put("_display_name", str);
        contentValues.put("mime_type", "image/jpeg");
        return context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
    }
}