Commit 1c959ce9 by yuichiro ogawa

#39283 ファイルダウンロード処理

parent 57d0dce7
......@@ -42,10 +42,9 @@ public class OnAppDownloadReceiver extends BroadcastReceiver {
cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
Log.d(TAG, "The file has been downloaded to: " + downloadedTo);
if (downloadedTo != null && downloadedTo.endsWith(".pdf")) {
if (downloadedTo != null && !downloadedTo.endsWith(".apk")) {
Toast.makeText(context, context.getResources().getString(R.string.download_success), //To notify the Client that the file is being downloaded
Toast.LENGTH_LONG).show();
// PDFファイルの場合はAPK用の処理は通過させない
return;
}
}
......
......@@ -20,11 +20,14 @@ import android.security.NetworkSecurityPolicy;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.CookieManager;
import android.webkit.DownloadListener;
import android.webkit.JavascriptInterface;
import android.webkit.JsResult;
import android.webkit.URLUtil;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
......@@ -35,6 +38,8 @@ import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
......@@ -112,8 +117,11 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
mChatWebView.setOverScrollMode(View.OVER_SCROLL_NEVER); //オーバースクロールしない。
mChatWebView.setVerticalScrollBarEnabled(false); //スクロールバーを消す。
mChatWebView.getSettings().setJavaScriptEnabled(true); //Javascriptを有効にする。
// mChatWebView.setWebContentsDebuggingEnabled(true);
WebSettings settings = mChatWebView.getSettings();
settings.setJavaScriptEnabled(true); //Javascriptを有効にする。
settings.setAppCacheEnabled(false);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
if (Logger.isDebugEnabled()) {
mChatWebView.setWebContentsDebuggingEnabled(true); //デバッグモード(chromeからinspect可)
}
......@@ -268,9 +276,26 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Uri uri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(uri);
final String fileName = uri.getQueryParameter("fileName");
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
//------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setTitle(fileName);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
if (dm != null) {
dm.enqueue(request);
}
Toast.makeText(getApplicationContext(), getString(R.string.download_start), //To notify the Client that the file is being downloaded
Toast.LENGTH_LONG).show();
}
});
......@@ -317,7 +342,7 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
} else { // その他のファイルはurlのみ確認
Logger.d("download ", "download URL :" + url);
}
return true;
return false;
}
// @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment