本文整理汇总了Java中android.webkit.DownloadListener类的典型用法代码示例。如果您正苦于以下问题:Java DownloadListener类的具体用法?Java DownloadListener怎么用?Java DownloadListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DownloadListener类属于android.webkit包,在下文中一共展示了DownloadListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setDownloadListener
import android.webkit.DownloadListener; //导入依赖的package包/类
private void setDownloadListener(List<DownLoadResultListener> downLoadResultListeners, boolean isParallelDl, int icon) {
DownloadListener mDownloadListener = this.mDownloadListener;
if (mDownloadListener == null) {
this.mDownloadListener = mDownloadListener = new DefaultDownLoaderImpl.Builder().setActivity(mActivity)
.setEnableIndicator(true)//
.setForce(false)//
.setDownLoadResultListeners(downLoadResultListeners)//
.setDownLoadMsgConfig(mDefaultMsgConfig.getDownLoadMsgConfig())//
.setParallelDownload(isParallelDl)//
.setPermissionInterceptor(this.mPermissionInterceptor)
.setIcon(icon)
.setWebView(this.mWebCreator.get())
.create();
}
}
示例2: onCreate
import android.webkit.DownloadListener; //导入依赖的package包/类
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());
}
示例3: onCreate
import android.webkit.DownloadListener; //导入依赖的package包/类
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) {
}
}
});
}
}
示例4: setDefaultDownloadListener
import android.webkit.DownloadListener; //导入依赖的package包/类
/**
* 设置下载监听器,默认使用浏览器下载
*/
private void setDefaultDownloadListener() {
setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition,
String mimeType,
long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW);
String downLoadUrl = url;
if (!downLoadUrl.contains("http://")) {
downLoadUrl = "http://" + downLoadUrl;
}
intent.setData(Uri.parse(downLoadUrl));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(intent);
}
});
}
示例5: createDownloadListener
import android.webkit.DownloadListener; //导入依赖的package包/类
private DownloadListener createDownloadListener() {
return new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
if (!AppConstants.supportsDownloadingFiles()) {
return;
}
final String scheme = Uri.parse(url).getScheme();
if (scheme == null || (!scheme.equals("http") && !scheme.equals("https"))) {
// We are ignoring everything that is not http or https. This is a limitation of
// Android's download manager. There's no reason to show a download dialog for
// something we can't download anyways.
Log.w(TAG, "Ignoring download from non http(s) URL: " + url);
return;
}
if (callback != null) {
final Download download = new Download(url, userAgent, contentDisposition, mimetype, contentLength, Environment.DIRECTORY_DOWNLOADS);
callback.onDownloadStart(download);
}
}
};
}
示例6: getMimeType
import android.webkit.DownloadListener; //导入依赖的package包/类
public static String getMimeType(File file){
String suffix = getSuffix(file);
if (suffix == null) {
return "file/*";
}
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(suffix);
if (type != null || !type.isEmpty()) {
return type;
}
WebView webView = new WebView(null);
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype, long contentLength) {
}
});
return "file/*";
}
示例7: getDownloadListener
import android.webkit.DownloadListener; //导入依赖的package包/类
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);
}
};
}
示例8: getDownloadListener
import android.webkit.DownloadListener; //导入依赖的package包/类
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();
}
}
};
}
示例9: init
import android.webkit.DownloadListener; //导入依赖的package包/类
protected void init(Context context) {
if (context instanceof Activity) {
mActivity = new WeakReference<Activity>((Activity) context);
}
initProgress(context);
initWebSettings();
initWebViewClient();
initWebChromeClient();
setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
if (mWebViewClientListener != null) {
mWebViewClientListener.onDownloadRequested(url, userAgent, contentDisposition, mimetype, contentLength);
}
}
});
}
示例10: onCreate
import android.webkit.DownloadListener; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebView = new HTML5CustomWebView(this, HTML5WebViewCustomAD.this,title,ad_url);
mWebView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
//准备javascript注入
mWebView.addJavascriptInterface(
new Js2JavaInterface(),"Js2JavaInterface");
if (savedInstanceState != null) {
mWebView.restoreState(savedInstanceState);
} else {
if (ad_url != null) {
mWebView.loadUrl(ad_url);
}
}
setContentView(mWebView.getLayout());
}
示例11: findView
import android.webkit.DownloadListener; //导入依赖的package包/类
@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);
}
示例12: initWebKit
import android.webkit.DownloadListener; //导入依赖的package包/类
protected void initWebKit() {
removeSearchBoxJavaBridgeInterface();
setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
if (WebConfig.getDownloadListener() != null) {
WebConfig.getDownloadListener().onDownloadStart(url, userAgent, contentDisposition, mimetype, contentLength);
} else {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
getContext().startActivity(intent);
}
}
});
if (Build.VERSION.SDK_INT >= 9) {
setOverScrollMode(View.OVER_SCROLL_NEVER);
}
getSettings().setJavaScriptEnabled(true);
getSettings().setDomStorageEnabled(true);
getSettings().setDatabaseEnabled(true);
getSettings().setBuiltInZoomControls(false);
getSettings().setAppCacheEnabled(true);
if (Build.VERSION.SDK_INT >= 19) {
getSettings().setLoadsImagesAutomatically(true);
} else {
getSettings().setLoadsImagesAutomatically(false);
}
getSettings().setDefaultTextEncodingName("UTF-8");
}
示例13: onCreate
import android.webkit.DownloadListener; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("使用教程");
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
webview = (ProgressWebView) findViewById(R.id.webview);
// ~~~ 设置数据
webview.setVerticalScrollbarOverlay(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setAllowFileAccess(true);
webview.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
if (url != null
&& (url.startsWith("http://") || url
.startsWith("file:///")))
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
webview.loadUrl(Config.HELP_PAGE);
}
示例14: setDownloadListener
import android.webkit.DownloadListener; //导入依赖的package包/类
@Override
public void setDownloadListener(DownloadListener listener) {
if (listener == mDefaultDownloadListener) {
super.setDownloadListener(listener);
} else {
mDelegateDownloadListener = listener;
}
}
示例15: onCreate
import android.webkit.DownloadListener; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!getIntent().getBooleanExtra(IsShowAnimation, true)) {
overridePendingTransition(0, 0);
}
setContentView(R.layout.activity_webview);
wv = (WebView) findViewById(R.id.wv);
mSRLList = (SwipeRefreshLayout) findViewById(R.id.mSRL);
mSRLList.setOnRefreshListener(this);
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
WebSettings ws = wv.getSettings();
ws.setDomStorageEnabled(true);
// ws.setUserAgentString("android.xl-"+ ChannelUtil.getChannel(this)+"-"+ ChannelUtil.getVersionName(this));
ws.setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
wv.setWebChromeClient(new ChromeClient());
wv.setWebViewClient(new WebClient());
wv.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
url = getIntent().getStringExtra(Param_Url);
if (TextUtils.isEmpty(url)) {
url = "file:///android_asset/test.html";
}
mTitle = getIntent().getStringExtra(Param_Title);
canShare = getIntent().getBooleanExtra(Param_CanShare, false);
initShare(url, mTitle);
setCookie(url);
wv.loadUrl(url);
}