Fixed images cannot be saved. Fixed crashes when downloading videos

This commit is contained in:
Alex Ning 2019-09-11 00:30:15 +08:00
parent f5f2acfab1
commit f109d28c9d
2 changed files with 32 additions and 16 deletions

View File

@ -426,22 +426,6 @@ public class ViewImageActivity extends AppCompatActivity {
@Override
protected Void doInBackground(Void... params) {
try {
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
File directory = new File(path + "/Infinity/");
if(!directory.exists()) {
if(!directory.mkdir()) {
saveSuccess = false;
return null;
}
} else {
if(directory.isFile()) {
if(!directory.delete() && !directory.mkdir()) {
saveSuccess = false;
return null;
}
}
}
//Android Q support
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ContentValues values = new ContentValues();
@ -478,6 +462,22 @@ public class ViewImageActivity extends AppCompatActivity {
values.put(MediaStore.Images.Media.IS_PENDING, 0);
resolver.update(item, values, null, null);
} else {
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
File directory = new File(path + "/Infinity/");
if(!directory.exists()) {
if(!directory.mkdir()) {
saveSuccess = false;
return null;
}
} else {
if(directory.isFile()) {
if(!directory.delete() && !directory.mkdir()) {
saveSuccess = false;
return null;
}
}
}
File file = new File(path + "/Infinity/", mImageFileName + ".jpg");
int postfix = 1;
while(file.exists()) {

View File

@ -51,6 +51,8 @@ import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import java.io.File;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -395,6 +397,20 @@ public class ViewVideoActivity extends AppCompatActivity {
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, mGifOrVideoFileName);
} else {
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
File directory = new File(path + "/Infinity/");
if(!directory.exists()) {
if(!directory.mkdir()) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, mGifOrVideoFileName);
}
} else {
if(directory.isFile()) {
if(!directory.delete() && !directory.mkdir()) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, mGifOrVideoFileName);
}
}
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", mGifOrVideoFileName);
}