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(); Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return -1; return -1;
} }
final String fileName = URLUtil.guessFileName(url, null, null); try {
request.allowScanningByMediaScanner(); final String fileName = URLUtil.guessFileName(url, null, null);
String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.DIRECTORY_DOWNLOADS); request.allowScanningByMediaScanner();
request.setDestinationInExternalPublicDir(myDir, fileName); String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.DIRECTORY_DOWNLOADS);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(myDir, fileName);
DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
assert dm != null; DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
return dm.enqueue(request); 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) { 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="added_to_story">Media successfully added to your story!</string>
<string name="action_disabled">Action disabled</string> <string name="action_disabled">Action disabled</string>
<string name="action_unfollow">Unfollow</string> <string name="action_unfollow">Unfollow</string>
<string name="error_destination_path">Something went wrong, please check your download directory in settings.</string>
</resources> </resources>