android.webkit.DownloadListener Java Examples

The following examples show how to use android.webkit.DownloadListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LetvWebViewActivity.java    From letv with Apache License 2.0 6 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
    LogInfo.log("lxx", "LetvWebViewActivity onCreate");
    setNeedStatistics(true);
    super.onCreate(savedInstanceState);
    this.mWebView = getWebView();
    if (TextUtils.isEmpty(this.loadType) || !this.loadType.equals(LetvUtils.getString(R.string.letv_protol_name))) {
        this.mWebView.getSettings().setJavaScriptEnabled(true);
    } else {
        this.mWebView.getSettings().setJavaScriptEnabled(false);
    }
    this.mWebView.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            LogInfo.log("LXF", LetvWebViewActivity.this.loadType + "<<-----------download url------------>>" + url);
            LogInfo.log("lxx", "DownloadListener,url: " + url + ",userAgent: " + userAgent + ",mimetype: " + mimetype + ",contentDisposition: " + contentDisposition + ",contentLength: " + contentLength);
            ApkDownloadAsyncTask.downloadApk(LetvWebViewActivity.this, url, LetvWebViewActivity.this.loadType);
            LetvWebViewActivity.this.finish();
        }
    });
    this.mWebView.setWebViewClient(new LetvWebViewClient());
}
 
Example #2
Source File: LetvSearchWebViewActivity.java    From letv with Apache License 2.0 6 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
    LogInfo.log("clf", "LetvSearchWebViewActivity");
    setNeedStatistics(true);
    super.onCreate(savedInstanceState);
    this.mWebView = getWebView();
    if (this.mWebView != null) {
        this.mWebView.getSettings().setUserAgentString(LetvUtils.createUA(this.mWebView.getSettings().getUserAgentString(), this));
        this.mWebView.setWebViewClient(new LetvWebViewClient());
        this.mWebView.setDownloadListener(new DownloadListener() {
            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
                try {
                    LetvSearchWebViewActivity.this.mContext.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));
                } catch (Exception e) {
                }
            }
        });
    }
}
 
Example #3
Source File: RexxarWebViewCore.java    From rexxar-android with MIT License 6 votes vote down vote up
protected DownloadListener getDownloadListener() {
    return new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition,
                                    String mimeType, long contentLength) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            Uri uri = Uri.parse(url);
            intent.setData(uri);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                getContext().startActivity(intent);
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
            }
        }
    };
}
 
Example #4
Source File: WebViewActivity.java    From mattermost-android-classic with Apache License 2.0 6 votes vote down vote up
private DownloadListener getDownloadListener() {
    return new DownloadListener() {
        public void onDownloadStart(
            String url,
            String userAgent,
            String contentDisposition,
            String mimetype,
            long contentLength
        ) {
            Uri uri = Uri.parse(url);
            Request request = new Request(uri);
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setTitle("File download from Mattermost");

            String cookie = CookieManager.getInstance().getCookie(url);
            if (cookie != null) {
                request.addRequestHeader("cookie", cookie);
            }

            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            dm.enqueue(request);
       }
    };
}
 
Example #5
Source File: CompatWebView.java    From Android_Skin_2.0 with Apache License 2.0 5 votes vote down vote up
@Override
public void setDownloadListener(DownloadListener listener) {
	if (listener == mDefaultDownloadListener) {
		super.setDownloadListener(listener);
	} else {
		mDelegateDownloadListener = listener;
	}
}
 
Example #6
Source File: AgentWebSettingsImpl.java    From AgentWeb with Apache License 2.0 5 votes vote down vote up
@Override
public WebListenerManager setDownloader(WebView webView, DownloadListener downloadListener) {
    if (downloadListener == null) {
        downloadListener = DefaultDownloadImpl.create(mAgentWeb.getActivity(), webView, mAgentWeb.getPermissionInterceptor());
    }
    return super.setDownloader(webView, downloadListener);
}
 
Example #7
Source File: InviteWebviewimpl.java    From letv with Apache License 2.0 5 votes vote down vote up
@SuppressLint({"AddJavascriptInterface"})
private void findView() {
    this.mWebView = getWebView();
    this.mWebView.getSettings().setCacheMode(2);
    this.mWebView.addJavascriptInterface(new JavaScriptinterface(this, this.mWebView, null), "LetvJSBridge_For_Android");
    this.mWebView.setWebViewClient(new LetvWebViewClient());
    this.mWebView.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            ApkDownloadAsyncTask.downloadApk(InviteWebviewimpl.this, url, "Invite");
            InviteWebviewimpl.this.finish();
        }
    });
    LogInfo.log("+->", "loadURL--->>>" + this.loadUrl);
    LogInfo.log("+->", "baseUrl--->>>" + this.baseUrl);
}
 
Example #8
Source File: Html5Activity.java    From ClassSchedule with Apache License 2.0 4 votes vote down vote up
@SuppressLint("JavascriptInterface")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);

    mSmoothProgress = findViewById(R.id.smooth_progress);

    Bundle bundle = getIntent().getBundleExtra("bundle");
    mUrl = bundle.getString("url");
    mTitle = bundle.getString("title", "");
    mJavaScriptInterface = bundle.getSerializable("javascript");

    initBackToolbar(TextUtils.isEmpty(mTitle) ? "加载中" : mTitle);

    Log.d("Url:", mUrl);
    Log.d("mTitle:", mTitle);


    mLayout = (LinearLayout) findViewById(R.id.web_layout);


    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mWebView = new WebView(getApplicationContext());
    mWebView.setLayoutParams(params);
    mLayout.addView(mWebView);

    WebSettings mWebSettings = mWebView.getSettings();
    mWebSettings.setSupportZoom(true);
    mWebSettings.setLoadWithOverviewMode(true);
    mWebSettings.setUseWideViewPort(true);
    mWebSettings.setDefaultTextEncodingName("utf-8");
    mWebSettings.setLoadsImagesAutomatically(true);

    //调用JS方法.安卓版本大于17,加上注解 @JavascriptInterface
    mWebSettings.setJavaScriptEnabled(true);

    if (mJavaScriptInterface != null) {
        mWebView.addJavascriptInterface(mJavaScriptInterface, "android");
    }

    mWebView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            downloadByBrowser(url);
        }
    });

    saveData(mWebSettings);

    newWin(mWebSettings);

    mWebView.setWebChromeClient(webChromeClient);


    mWebView.setWebViewClient(webViewClient);
    mWebView.loadUrl(mUrl);
}
 
Example #9
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void downloadListener(DownloadListener arg) {
  return BaseDSL.attr("downloadListener", arg);
}
 
Example #10
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void downloadListener(DownloadListener arg) {
  return BaseDSL.attr("downloadListener", arg);
}
 
Example #11
Source File: ShadowWebView.java    From materialistic with Apache License 2.0 4 votes vote down vote up
public DownloadListener getDownloadListener() {
    return downloadListener;
}
 
Example #12
Source File: ShadowWebView.java    From materialistic with Apache License 2.0 4 votes vote down vote up
@Implementation
public void setDownloadListener(DownloadListener listener) {
    downloadListener = listener;
}
 
Example #13
Source File: ZbigzFragment.java    From video-player with MIT License 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View InputFragmentView = inflater.inflate(R.layout.fragment_zbigz, container, false);
    tWebView = (WebView) InputFragmentView.findViewById(R.id.zbigz_web_view);
    tProgressBar = (ProgressBar) InputFragmentView.findViewById(R.id.zbigz_progress_bar);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        tWebView.getSettings().setAllowContentAccess(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        tWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
        tWebView.getSettings().setAllowFileAccessFromFileURLs(true);
    }

    tWebView.getSettings().setAppCacheEnabled(true);
    tWebView.getSettings().setAllowFileAccess(true);
    tWebView.getSettings().setDatabaseEnabled(true);
    tWebView.getSettings().setDomStorageEnabled(true);
    tWebView.getSettings().setSaveFormData(true);
    tWebView.getSettings().setJavaScriptEnabled(true);
    tWebView.setWebViewClient(new WebViewClient());

    tWebView.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            mListener.onZbigzFragmentInteraction(url);
        }
    });

    tWebView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            if (progress < 100 && tProgressBar.getVisibility() == ProgressBar.GONE) {
                tProgressBar.setVisibility(ProgressBar.VISIBLE);
                tWebView.setVisibility(WebView.GONE);
            }
            tProgressBar.setProgress(progress);
            if (progress == 100) {
                tProgressBar.setVisibility(ProgressBar.GONE);
                tWebView.setVisibility(WebView.VISIBLE);
            }
        }
    });

    tWebView.loadUrl("http://m.zbigz.com/");
    return InputFragmentView;
}
 
Example #14
Source File: APIWebViewActivity.java    From CustomActionWebView with MIT License 4 votes vote down vote up
/**
 * 配置webView
 */
void setWebView() {
    //声明WebSettings子类
    WebSettings webSettings = mWebView.getSettings();

    //支持Javascript交互
    webSettings.setJavaScriptEnabled(true);


    //设置自适应屏幕,两者合用
    webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
    webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小

    //缩放操作
    webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。
    webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放
    webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件

    //其他细节操作
    //webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存
    webSettings.setAllowFileAccess(true); //设置可以访问文件

    //对于不需要使用 file 协议的应用,禁用 file 协议;防止文件泄密,file协议即是file://
    //webSettings.setAllowFileAccess(false);
    //webSettings.setAllowFileAccessFromFileURLs(false);
    //webSettings.setAllowUniversalAccessFromFileURLs(false);



    webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
    webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
    webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式

    mWebView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            //网页中触发下载动作
        }
    });

    //增加js交互接口
    mWebView.addJavascriptInterface(new JsCallAndroidInterface(), "JSCallBackInterface");
}
 
Example #15
Source File: CustomSettings.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WebListenerManager setDownloader(WebView webView, DownloadListener downloadListener) {
	return super.setDownloader(webView,
			DefaultDownloadImpl.create((Activity) webView.getContext()
					, webView, mAgentWeb.getPermissionInterceptor()));
}
 
Example #16
Source File: ProWebView.java    From prowebview with Apache License 2.0 4 votes vote down vote up
/**
 * @see WebView#setDownloadListener(DownloadListener)
 * @deprecated Avoid calling this method. Use {@link #setProClient(ProClient)} instead
 */
@Override
@Deprecated
public void setDownloadListener(DownloadListener listener) {
    throw new UnsupportedOperationException("Avoid calling this method. Use setProClient(ProClient) instead.");
}
 
Example #17
Source File: AbsAgentWebSettings.java    From AgentWeb with Apache License 2.0 4 votes vote down vote up
@Override
public WebListenerManager setDownloader(WebView webView, DownloadListener downloadListener) {
    webView.setDownloadListener(downloadListener);
    return this;
}
 
Example #18
Source File: CustomSettings.java    From AgentWeb with Apache License 2.0 4 votes vote down vote up
@Override
public WebListenerManager setDownloader(WebView webView, DownloadListener downloadListener) {
    return super.setDownloader(webView,
            DefaultDownloadImpl.create(this.mActivity
                    , webView, mAgentWeb.getPermissionInterceptor()));
}
 
Example #19
Source File: BaseWebView.java    From dcs-sdk-java with Apache License 2.0 4 votes vote down vote up
public void setDownloadListener(DownloadListener listener) {
    super.setDownloadListener(listener);
}
 
Example #20
Source File: WebListenerManager.java    From AgentWeb with Apache License 2.0 votes vote down vote up
WebListenerManager setDownloader(WebView webView, DownloadListener downloadListener);