Open chenchi0920 opened 5 years ago
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ParcelFileDescriptor pfd = null;
try {
pfd = Tiny.getInstance().getApplication().getContentResolver().openFileDescriptor(uri, "r");
if (pfd != null) {
fis = new FileInputStream(pfd.getFileDescriptor());
byte[] decodeBytes = CompressKit.transformToByteArray(fis);
if (options.isKeepSampling) {
BitmapFactory.Options decodeOptions = CompressKit.getDefaultDecodeOptions();
decodeOptions.inPreferredConfig = options.config;
result[0] = BitmapFactory.decodeByteArray(decodeBytes, 0, decodeBytes.length, decodeOptions);
} else {
result[0] = BitmapCompressor.compress(decodeBytes, options, true);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (pfd != null) {
pfd.close();
}
if (fis != null)
fis.close();
}
}
适配完的读取文件
public static Bitmap shouldKeepSampling(Uri uri, final Tiny.FileCompressOptions options) throws Exception { if (uri == null) return null;
在Android Q上直接new File()在去判断是否存在会失败