我正在使用聊天应用程序。直到Android 28sdk都可以正常工作,但是当我拒绝androidx遇到此问题后,请检查下面的代码和错误截图。
private void compressAndUpload(final Context context, final String child, final File file) {
compressionTask = new AsyncTask<File, Void, String>() {
@Override
protected String doInBackground(File... files) {
String filePathCompressed = null;
Uri originalFileUri = Uri.fromFile(files[0]);
File tempFile = new File(context.getCacheDir(), originalFileUri.getLastPathSegment());
//tempFile = File.createTempFile(originalFileUri.getLastPathSegment(), null, context.getCacheDir());
if (child.equals("images")) {
filePathCompressed = SiliCompressor.with(context).compress(originalFileUri.toString(), tempFile);
} else {
try {
filePathCompressed = SiliCompressor.with(context).compressVideo(files[0].getPath(), context.getCacheDir().getPath());
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
if (filePathCompressed == null)
filePathCompressed = "";
return filePathCompressed;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
File compressed = new File(s);
fileUri = Uri.fromFile(compressed.length() > 0 ? compressed : file);
FirebaseStorage storage = FirebaseStorage.getInstance();
if (uploadRef == null)
uploadRef = storage.getReference().child(child).child(fileUri.getLastPathSegment());
if (replace) {
upload();
} else {
checkIfExists();
}
}
};
compressionTask.execute(file);
}