Nowadays the built-in Android browser has been replaced by Chrome, which does this perfectly well. You can long-press and save virtually any image or link, and even videos from a number of sites that couldn't be easily done on the desktop.
Answer below for older devices:
The Android browser by default can only download files that the Android system "recognizes" (i.e., there has to be a program registered to handle that file type). It's a stupid restriction in my opinion, but you can install Download Crutch to overcome this limitation (it registers itself for every filetype).
If you're referring to images that link to something else and you want to save the something else, long-press on the image and choose "Save Link As" or similar.
Answer from Matthew Read on Stack ExchangeNowadays the built-in Android browser has been replaced by Chrome, which does this perfectly well. You can long-press and save virtually any image or link, and even videos from a number of sites that couldn't be easily done on the desktop.
Answer below for older devices:
The Android browser by default can only download files that the Android system "recognizes" (i.e., there has to be a program registered to handle that file type). It's a stupid restriction in my opinion, but you can install Download Crutch to overcome this limitation (it registers itself for every filetype).
If you're referring to images that link to something else and you want to save the something else, long-press on the image and choose "Save Link As" or similar.
Personally I usually just click the link of the file and it downloads.
As for the image: try long pressing but instead of choosing "Save As" look for "Copy link URL" or "Open in New Window" or something similar to those two menu options. "Copy link URL" should copy the URL of the file to your clipboard, then you can paste that link in the address bar and hit "Go" and it should download your file. "Open in New Window" should essentially do the same thing (i'm just trying to give you as many options as I can to try). If you click on the link it may not take you anywhere but to a blank page while the file downloads.
So to check your download list: You may have already tried this but to see if the file was downloaded you can open your browser, open the menu, then select "More", you should see "Downloads". This is where your downloaded files list is.
Another way you could check is to look in the "downloads" folder on your sdcard (/sdcard/downloads/) using ES File Explorer or some other file explorer.
If this is not a solution let me know and give an example of what you are trying to accomplish and I'll try to figure it out.
Videos
Use https://pub.dartlang.org/packages/flutter_downloader. Don't forget to do platform configurations.
Basically, this is how you should use the package. There is a detailed long example in the link.
final taskId = await FlutterDownloader.enqueue(
url: 'your download link',
savedDir: 'the path of directory where you want to save downloaded files',
showNotification: true, // show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);
Edit: Some people said the package on top is not well maintained. Try this one https://pub.dev/packages/flowder
static var httpClient = new HttpClient();
Future<File> _downloadFile(String url, String filename) async {
var request = await httpClient.getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$filename');
await file.writeAsBytes(bytes);
return file;
}
How to download file from Url
fun downloadPdf(baseActivity:Context,url: String?,title: String?): Long {
val direct = File(Environment.getExternalStorageDirectory().toString() + "/your_folder")
if (!direct.exists()) {
direct.mkdirs()
}
val extension = url?.substring(url.lastIndexOf("."))
val downloadReference: Long
var dm: DownloadManager
dm= baseActivity.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val uri = Uri.parse(url)
val request = DownloadManager.Request(uri)
request.setDestinationInExternalPublicDir(
"/your_folder",
"pdf" + System.currentTimeMillis() + extension
)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setTitle(title)
Toast.makeText(baseActivity, "start Downloading..", Toast.LENGTH_SHORT).show()
downloadReference = dm?.enqueue(request) ?: 0
return downloadReference
}
Bofore calling this method do check for Runtime permission:
Manifest.permission.WRITE_EXTERNAL_STORAGE
Please try this code
public void downloadPdf(String url, String sem, String title, String branch) {
Uri Download_Uri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
//Restrict the types of networks over which this download may proceed.
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
//Set whether this download may proceed over a roaming connection.
request.setAllowedOverRoaming(false);
//Set the title of this download, to be displayed in notifications (if enabled).
request.setTitle("Downloading");
//Set a description of this download, to be displayed in notifications (if enabled)
request.setDescription("Downloading File");
//Set the local destination for the downloaded file to a path within the application's external files directory
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, title + "_" + branch + "_" + sem + "Year" + System.currentTimeMillis() + ".pdf");
request.allowScanningByMediaScanner();
request. setNotificationVisibility(DownloadManager.Request. VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION)
//Enqueue a new download and same the referenceId
downloadReference = downloadManager.enqueue(request);
}
attach broadcast receiver
BroadcastReceiver attachmentDownloadCompleteReceive = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(
DownloadManager.EXTRA_DOWNLOAD_ID, 0);
openDownloadedAttachment(context, downloadId);
}
}
};
private void openDownloadedAttachment(final Context context, final long downloadId) {
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadId);
Cursor cursor = downloadManager.query(query);
if (cursor.moveToFirst()) {
int downloadStatus = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
String downloadLocalUri = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
String downloadMimeType = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE));
if ((downloadStatus == DownloadManager.STATUS_SUCCESSFUL) && downloadLocalUri != null) {
openDownloadedAttachment(context, Uri.parse(downloadLocalUri), downloadMimeType);
}
}
cursor.close();
}
Hello, I have a reoccuring problem. Every time someone sends me a file in pdf format on for example Meta Messenger, my phone can't just download the file, it asks me to convert it to Google Docs pdf. But when in does, the file ends up being messed up to say gently.
When I receive same pdf via e-mail, there's no problem, I just click the attachment and phone downloads it without converting. Minor issue, but I'm tired of asking friends to re-send every file via e-mail, do you know any fix?
My phone is Google Pixel 6a with the newest Android I believe
Using Async task
call when you want to download file : new DownloadFileFromURL().execute(file_url);
public class MainActivity extends Activity {
// Progress Dialog
private ProgressDialog pDialog;
public static final int progress_bar_type = 0;
// File url to download
private static String file_url = "http://www.qwikisoft.com/demo/ashade/20001.kml";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DownloadFileFromURL().execute(file_url);
}
/**
* Showing Dialog
* */
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type: // we set this to 0
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading file. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
return pDialog;
default:
return null;
}
}
/**
* Background Async Task to download file
* */
class DownloadFileFromURL extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Bar Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}
/**
* Downloading file in background thread
* */
@Override
protected String doInBackground(String... f_url) {
int count;
try {
URL url = new URL(f_url[0]);
URLConnection connection = url.openConnection();
connection.connect();
// this will be useful so that you can show a tipical 0-100%
// progress bar
int lenghtOfFile = connection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(url.openStream(),
8192);
// Output stream
OutputStream output = new FileOutputStream(Environment
.getExternalStorageDirectory().toString()
+ "/2011.kml");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress("" + (int) ((total * 100) / lenghtOfFile));
// writing data to file
output.write(data, 0, count);
}
// flushing output
output.flush();
// closing streams
output.close();
input.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
return null;
}
/**
* Updating progress bar
* */
protected void onProgressUpdate(String... progress) {
// setting progress percentage
pDialog.setProgress(Integer.parseInt(progress[0]));
}
/**
* After completing background task Dismiss the progress dialog
* **/
@Override
protected void onPostExecute(String file_url) {
// dismiss the dialog after the file was downloaded
dismissDialog(progress_bar_type);
}
}
}
if not working in 4.0 then add:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Simple kotlin version
fun download(link: String, path: String) {
URL(link).openStream().use { input ->
FileOutputStream(File(path)).use { output ->
input.copyTo(output)
}
}
}
is there anyway to get the download progress or downloaded size from this method ?
This is the same realization as defined in InputStream.copyTo, but with progress
/*inline*/ fun download(link: String, path: String, progress: ((Long, Long) -> Unit)? = null): Long {
val url = URL(link)
val connection = url.openConnection()
connection.connect()
val length = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) connection.contentLengthLong else
connection.contentLength.toLong()
url.openStream().use { input ->
FileOutputStream(File(path)).use { output ->
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
var bytesRead = input.read(buffer)
var bytesCopied = 0L
while (bytesRead >= 0) {
output.write(buffer, 0, bytesRead)
bytesCopied += bytesRead
progress?.invoke(bytesCopied, length)
bytesRead = input.read(buffer)
}
return bytesCopied
}
}
}
An example of usage:
val handler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) {
// length may be negative because it is based on http header
val (progress, length) = msg.obj as Pair<Long, Long>
}
}
// call this outside of main thread
val totalSize = download("http://example.site/path/to/file", "path/to/file") { progress, length ->
// handling the result on main thread
handler.sendMessage(handler.obtainMessage(0, progress to length))
}
Discord mobile sucks so images from bot embeds save the title instead (so i have a bunch of files named "Pinterest (pinterest.com)" etc. instead of the actual name) but the share button gives you an actual link. Is there an app to download this url so it's quicker than opening in browser and saving from there and tabbing back to discord. this is the share menu in question
all googling is giving me is stack overflow posts from Android devs writing apps and no actual apps to do this
Download File from URL
There are a couple ways to do this. As mentioned, using the developer tools could work (more likely it will give you the url to the file) and right-clicking the link will work. Alternatively there are these options.
In Chrome
- Go to the URL
- Right-click the webpage
- Select Save As...
For verification purposes, here are png, jpg, and mp3 links. Follow them and try these steps. However, in my experience. If you already have a url to a file, opening up Chrome and following these steps is rather tedious so here is an alternative.
In Command Line
- Open your favorite terminal emulator
- type
curl -O URL
- Where
Ois written in capital - And
URLis the URL to the file, e.g.http://example.com/file.mp3
For Powershell, this example works great:
invoke-webrequest -uri http://files.animatedsuperheroes.com/themes/spiderman94.mp3 -outfile "c:\Spiderman94.mp3"
This was confirmed with Win10 x64 1607.
I want to download this video file using my phone somehow: https://i.imgur.com/6ro0m3w.mp4 This should be easy right? Can you do it using an app that's not specific to imgur?
I can view it and stream it just fine using Firefox, Chrome, VLC, Podcast Addict, cast it using Solid Explorer but none of them can save the video unless I'm missing something.
The Sync For Reddit link handler can't handle this video for some reason, if I try to download it using Firefox then I get a tiny broken .mp4 file.
I bet there are many apps that can download videos like nobody's business but what if I want to download a web page as an .html file? An Mp3? Any file that other apps can display from an URL?
I want a link handler that can download files using any link that other apps can open, or an app that lets me paste this link into it and downloads the file. Anyone know of an app like that?
Or alternatively is there a video app that can open a video link like this but it also let's you save the video?
EDIT: after posting this using sync for reddit I can click the mp4 link without problems and save it, weird that it did not work before... Still, the question still stands, can this it can be done without an app that is designed with imgur links in mind or from other web sites?
I have seen something like this before, can't remember what though. I'll look for it.
I can download this video using chrome (press and hold on the middle of the video) and Reddit is fun (there is a download button on the title bar).
I think chrome can save most of stuff tbh