mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
Fixed issues of saving images and videos on Android Q devices.
This commit is contained in:
parent
6f4367c459
commit
8c55fbbde9
@ -5,16 +5,21 @@ import android.animation.Animator;
|
|||||||
import android.animation.ArgbEvaluator;
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@ -437,17 +442,54 @@ public class ViewImageActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = new File(path + "/Infinity/", mImageFileName + ".jpg");
|
//Android Q support
|
||||||
int postfix = 1;
|
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
while(file.exists()) {
|
ContentValues values = new ContentValues();
|
||||||
file = new File(path + "/Infinity/", mImageFileName + "-" + postfix + ".jpg");
|
values.put(MediaStore.Images.Media.DISPLAY_NAME, mImageFileName + ".jpg");
|
||||||
|
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
|
||||||
|
values.put(MediaStore.Images.Media.IS_PENDING, 1);
|
||||||
|
|
||||||
|
ContentResolver resolver = getContentResolver();
|
||||||
|
Uri collection = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
||||||
|
Uri item = resolver.insert(collection, values);
|
||||||
|
|
||||||
|
if(item == null) {
|
||||||
|
saveSuccess = false;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (ParcelFileDescriptor pfd = resolver.openFileDescriptor(item, "w", null)) {
|
||||||
|
if(pfd == null) {
|
||||||
|
saveSuccess = false;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(pfd.getFileDescriptor());
|
||||||
|
resource.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
||||||
|
|
||||||
|
outputStream.flush();
|
||||||
|
outputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
saveSuccess = false;
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
values.clear();
|
||||||
|
values.put(MediaStore.Images.Media.IS_PENDING, 0);
|
||||||
|
resolver.update(item, values, null, null);
|
||||||
|
} else {
|
||||||
|
File file = new File(path + "/Infinity/", mImageFileName + ".jpg");
|
||||||
|
int postfix = 1;
|
||||||
|
while(file.exists()) {
|
||||||
|
file = new File(path + "/Infinity/", mImageFileName + "-" + (postfix++) + ".jpg");
|
||||||
|
}
|
||||||
|
OutputStream outputStream = new FileOutputStream(file);
|
||||||
|
|
||||||
|
resource.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
||||||
|
|
||||||
|
outputStream.flush();
|
||||||
|
outputStream.close();
|
||||||
}
|
}
|
||||||
OutputStream outputStream = new FileOutputStream(file);
|
|
||||||
|
|
||||||
resource.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
|
||||||
|
|
||||||
outputStream.flush();
|
|
||||||
outputStream.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
saveSuccess = false;
|
saveSuccess = false;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -385,9 +385,21 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
request.allowScanningByMediaScanner();
|
request.allowScanningByMediaScanner();
|
||||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", mGifOrVideoFileName);
|
|
||||||
|
//Android Q support
|
||||||
|
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, mGifOrVideoFileName);
|
||||||
|
} else {
|
||||||
|
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", mGifOrVideoFileName);
|
||||||
|
}
|
||||||
|
|
||||||
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
||||||
|
|
||||||
|
if(manager == null) {
|
||||||
|
Toast.makeText(this, R.string.download_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
manager.enqueue(request);
|
manager.enqueue(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user