mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +00:00 
			
		
		
		
	added check if directory exist and try create it
Also I added new variable `'final File dir`' with value of key "download_path_preference" or externalStorageDirectory. Firstly I check if dir exits, then eventually try to create it and next - download file.
This commit is contained in:
		| @@ -7,6 +7,7 @@ import android.content.DialogInterface; | |||||||
| import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||||
| import android.net.Uri; | import android.net.Uri; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
|  | import android.os.Environment; | ||||||
| import android.preference.PreferenceManager; | import android.preference.PreferenceManager; | ||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
| import android.support.v4.app.DialogFragment; | import android.support.v4.app.DialogFragment; | ||||||
| @@ -72,6 +73,17 @@ public class DownloadDialog extends DialogFragment { | |||||||
|                             default: |                             default: | ||||||
|                                 Log.d(TAG, "lolz"); |                                 Log.d(TAG, "lolz"); | ||||||
|                         } |                         } | ||||||
|  |                         //to avoid hard-coded string like "/storage/emulated/0/NewPipe" | ||||||
|  |                         final File dir = new File(defaultPreferences.getString( | ||||||
|  |                                 "download_path_preference", | ||||||
|  |                                 Environment.getExternalStorageDirectory().getAbsolutePath() + "/NewPipe")); | ||||||
|  |                         if(!dir.exists()) { | ||||||
|  |                             boolean mkdir = dir.mkdir(); //attempt to create directory | ||||||
|  |                             if(!mkdir && !dir.isDirectory()) { | ||||||
|  |                                 Log.e(TAG, "Cant' create directory named " + dir.toString()); | ||||||
|  |                                 //TODO notify user "download directory should be changed" ? | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|                         DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); |                         DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); | ||||||
|                         DownloadManager.Request request = new DownloadManager.Request( |                         DownloadManager.Request request = new DownloadManager.Request( | ||||||
|                                 Uri.parse(url)); |                                 Uri.parse(url)); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jacek Musiał
					Jacek Musiał