Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
save img compat
Browse files Browse the repository at this point in the history
  • Loading branch information
GuhDoy committed Aug 27, 2021
1 parent 5102a65 commit b803835
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions app/src/main/java/gm/tieba/tabswitch/hooker/add/SaveImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.ContentValues;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -96,8 +97,16 @@ private static void saveImage(String url, String title, int i, Context context)
try (var is = new URL(url).openStream()) {
var bb = FileUtils.toByteBuffer(is);
var newImageDetails = new ContentValues();
newImageDetails.put(MediaStore.MediaColumns.RELATIVE_PATH,
Environment.DIRECTORY_PICTURES + File.separator + "tieba" + File.separator + title);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
newImageDetails.put(MediaStore.MediaColumns.RELATIVE_PATH,
Environment.DIRECTORY_PICTURES + File.separator + "tieba" + File.separator + title);
} else {
var path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"tieba" + File.separator + title);
path.mkdirs();
newImageDetails.put(MediaStore.MediaColumns.DATA, path + File.separator
+ i + "." + FileUtils.getExtension(bb));
}
newImageDetails.put(MediaStore.MediaColumns.DISPLAY_NAME, String.valueOf(i));
newImageDetails.put(MediaStore.MediaColumns.MIME_TYPE, "image/" + FileUtils.getExtension(bb));
var resolver = context.getContentResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.ContentValues;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;

Expand Down Expand Up @@ -52,8 +53,16 @@ private int saveImage(String url, InputStream is, Context context) {
try {
var bb = FileUtils.toByteBufferNoCopy(is);
var newImageDetails = new ContentValues();
newImageDetails.put(MediaStore.MediaColumns.RELATIVE_PATH,
Environment.DIRECTORY_PICTURES + File.separator + "tieba");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
newImageDetails.put(MediaStore.MediaColumns.RELATIVE_PATH,
Environment.DIRECTORY_PICTURES + File.separator + "tieba");
} else {
var path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"tieba");
path.mkdirs();
newImageDetails.put(MediaStore.MediaColumns.DATA, path + File.separator
+ fileName + "." + FileUtils.getExtension(bb));
}
newImageDetails.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName);
newImageDetails.put(MediaStore.MediaColumns.MIME_TYPE, "image/" + FileUtils.getExtension(bb));
var resolver = appContext.getContentResolver();
Expand Down

0 comments on commit b803835

Please sign in to comment.