Commit f78cc649b83f48e36f478366498f20884c189235
1 parent
3dc5665b
1 修改编译版本测试,无法上传图片问题
Showing
3 changed files
with
42 additions
and
11 deletions
config.gradle
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/upload/UploadLogic.java
| ... | ... | @@ -2,6 +2,7 @@ package com.cnlive.moudle.pedometer.upload; |
| 2 | 2 | |
| 3 | 3 | import android.content.Context; |
| 4 | 4 | import android.media.MediaMetadataRetriever; |
| 5 | +import android.os.Build; | |
| 5 | 6 | import android.os.Environment; |
| 6 | 7 | import android.text.TextUtils; |
| 7 | 8 | import android.util.Log; |
| ... | ... | @@ -335,9 +336,25 @@ public class UploadLogic { |
| 335 | 336 | this.imageHeight = imageHeight; |
| 336 | 337 | } |
| 337 | 338 | } |
| 339 | +// | |
| 340 | +// private static String getPath(String cachePath) { | |
| 341 | +// String path = Environment.getExternalStorageDirectory() + cachePath; | |
| 342 | +// File file = new File(path); | |
| 343 | +// if (file.mkdirs()) { | |
| 344 | +// return path; | |
| 345 | +// } | |
| 346 | +// return path; | |
| 347 | +// } | |
| 338 | 348 | |
| 339 | - private static String getPath(String cachePath) { | |
| 349 | + /** | |
| 350 | + * 鲁班压缩后图片的存储位置 | |
| 351 | + * | |
| 352 | + * @return | |
| 353 | + */ | |
| 354 | + public static String getPath(Context context, String cachePath) { | |
| 340 | 355 | String path = Environment.getExternalStorageDirectory() + cachePath; |
| 356 | + if (Build.VERSION.SDK_INT >= 29) | |
| 357 | + path = context.getExternalFilesDir("").getAbsolutePath(); | |
| 341 | 358 | File file = new File(path); |
| 342 | 359 | if (file.mkdirs()) { |
| 343 | 360 | return path; |
| ... | ... | @@ -358,11 +375,11 @@ public class UploadLogic { |
| 358 | 375 | .action((BaseInfo<UploadAuthData> data, DataCallback<Map<String, Object>> callback) -> |
| 359 | 376 | Logic.process(() -> { |
| 360 | 377 | Map map = new HashMap(); |
| 361 | - File file = new File(getPath("/strike/cache/") + "share.jpg"); | |
| 378 | + File file = new File(getPath(context,"/strike/cache/") + "share.jpg"); | |
| 362 | 379 | if (file.exists()) { |
| 363 | - src = getPath("/strike/cache/") + "share.jpg"; | |
| 380 | + src = getPath(context,"/strike/cache/") + "share.jpg"; | |
| 364 | 381 | } else { |
| 365 | - src = getPath("/strike/cache/") + "sharefirst.jpg"; | |
| 382 | + src = getPath(context,"/strike/cache/") + "sharefirst.jpg"; | |
| 366 | 383 | } |
| 367 | 384 | map.put("image", src); |
| 368 | 385 | map.put("tocken", data.getData().getToken()); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/upload/UploadProvider.java
| ... | ... | @@ -224,7 +224,7 @@ public class UploadProvider { |
| 224 | 224 | Luban.with(context) |
| 225 | 225 | .load(imageFiles.get(i)) |
| 226 | 226 | .ignoreBy(500) |
| 227 | - .setTargetDir(getPath(TYPE_IMAGE_PATH)) | |
| 227 | + .setTargetDir(getPath(context, TYPE_IMAGE_PATH)) | |
| 228 | 228 | .filter(new CompressionPredicate() { |
| 229 | 229 | @Override |
| 230 | 230 | public boolean apply(String path) { |
| ... | ... | @@ -248,7 +248,7 @@ public class UploadProvider { |
| 248 | 248 | |
| 249 | 249 | @Override |
| 250 | 250 | public void onError(Throwable e) { |
| 251 | - Log.e(TAG, "onError: 失败"+e.getMessage() ); | |
| 251 | + Log.e(TAG, "onError: 失败" + e.getMessage()); | |
| 252 | 252 | // TODO 当压缩过程出现问题时调用 |
| 253 | 253 | AlertUtil.showDeftToast(context, "图片压缩失败,请重新上传"); |
| 254 | 254 | } |
| ... | ... | @@ -298,7 +298,7 @@ public class UploadProvider { |
| 298 | 298 | return; |
| 299 | 299 | } |
| 300 | 300 | //PLShortVideoTranscoder初始化,三个参数,第一个context,第二个要压缩文件的路径,第三个视频压缩后输出的路径 |
| 301 | - PLShortVideoTranscoder mShortVideoTranscoder = new PLShortVideoTranscoder(mContext, filepath, getPath(TYPE_VIDEO_PATH) + MD5.getFileMD5(new File(filepath)) + ".mp4"); | |
| 301 | + PLShortVideoTranscoder mShortVideoTranscoder = new PLShortVideoTranscoder(mContext, filepath, getPath(mContext,TYPE_VIDEO_PATH) + MD5.getFileMD5(new File(filepath)) + ".mp4"); | |
| 302 | 302 | MediaMetadataRetriever retr = new MediaMetadataRetriever(); |
| 303 | 303 | retr.setDataSource(filepath); |
| 304 | 304 | String height = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); // 视频高度 |
| ... | ... | @@ -357,9 +357,25 @@ public class UploadProvider { |
| 357 | 357 | 8000 * 1000, |
| 358 | 358 | }; |
| 359 | 359 | |
| 360 | +// | |
| 361 | +// private static String getPath(String cachePath) { | |
| 362 | +// String path = Environment.getExternalStorageDirectory() + cachePath; | |
| 363 | +// File file = new File(path); | |
| 364 | +// if (file.mkdirs()) { | |
| 365 | +// return path; | |
| 366 | +// } | |
| 367 | +// return path; | |
| 368 | +// } | |
| 360 | 369 | |
| 361 | - private static String getPath(String cachePath) { | |
| 370 | + /** | |
| 371 | + * 鲁班压缩后图片的存储位置 | |
| 372 | + * | |
| 373 | + * @return | |
| 374 | + */ | |
| 375 | + public static String getPath(Context context, String cachePath) { | |
| 362 | 376 | String path = Environment.getExternalStorageDirectory() + cachePath; |
| 377 | + if (Build.VERSION.SDK_INT >= 29) | |
| 378 | + path = context.getExternalFilesDir("").getAbsolutePath(); | |
| 363 | 379 | File file = new File(path); |
| 364 | 380 | if (file.mkdirs()) { |
| 365 | 381 | return path; |
| ... | ... | @@ -432,7 +448,6 @@ public class UploadProvider { |
| 432 | 448 | } |
| 433 | 449 | |
| 434 | 450 | |
| 435 | - | |
| 436 | 451 | private static List<MultipartBody.Part> getImageParams(List<String> imageFiles, ProgressCallback callback) { |
| 437 | 452 | List<MultipartBody.Part> imageParams = new ArrayList<>(); |
| 438 | 453 | |
| ... | ... | @@ -585,7 +600,6 @@ public class UploadProvider { |
| 585 | 600 | } |
| 586 | 601 | |
| 587 | 602 | |
| 588 | - | |
| 589 | 603 | private static RequestBody getRequestString(String value) { |
| 590 | 604 | RequestBody requestString = RequestBody.create(MediaType.parse("text/plain"), value); |
| 591 | 605 | return requestString; | ... | ... |