0
我的android應用程序可以從一個特定的文件模式(如* .pdf)從網址下載文件。如何知道文件無法在java/android中未經授權下載?
但是一些網址需要用戶的授權才能下載文件。我不想顯示這些網址的授權屏幕。我只是想傳達給用戶這個文件不能被這個應用程序下載。
我該如何在java/android中執行此操作?
void download(String url)
{
URL url = new URL(url);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//TODO : stop download if detected that this url requires authorization/authentication.
urlConnection.disconnect();
}
檢查您嘗試下載時獲得的[http status](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)? – 2016-05-16 06:48:34
獲取該網址的http響應代碼,如果是401則顯示登錄頁面。 – Gangaraju
m將響應碼作爲-1而不是401. :( –