Fix some issues

This commit is contained in:
tom79 2020-03-08 16:25:12 +01:00
parent ddbd76bf15
commit cbd74ffc8d
2 changed files with 15 additions and 8 deletions

View File

@ -1174,14 +1174,20 @@ public class Helper {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return -1;
}
final String fileName = URLUtil.guessFileName(url, null, null);
request.allowScanningByMediaScanner();
String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.DIRECTORY_DOWNLOADS);
request.setDestinationInExternalPublicDir(myDir, fileName);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
assert dm != null;
return dm.enqueue(request);
try {
final String fileName = URLUtil.guessFileName(url, null, null);
request.allowScanningByMediaScanner();
String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.DIRECTORY_DOWNLOADS);
request.setDestinationInExternalPublicDir(myDir, fileName);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
assert dm != null;
return dm.enqueue(request);
}catch (IllegalStateException e){
Toasty.error(context,context.getString(R.string.error_destination_path), Toast.LENGTH_LONG).show();
e.printStackTrace();
return -1;
}
}
public static String getMimeType(String url) {

View File

@ -1221,4 +1221,5 @@
<string name="added_to_story">Media successfully added to your story!</string>
<string name="action_disabled">Action disabled</string>
<string name="action_unfollow">Unfollow</string>
<string name="error_destination_path">Something went wrong, please check your download directory in settings.</string>
</resources>