本文整理汇总了Java中android.webkit.WebResourceRequest.getUrl方法的典型用法代码示例。如果您正苦于以下问题:Java WebResourceRequest.getUrl方法的具体用法?Java WebResourceRequest.getUrl怎么用?Java WebResourceRequest.getUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.WebResourceRequest
的用法示例。
在下文中一共展示了WebResourceRequest.getUrl方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldInterceptRequest
import android.webkit.WebResourceRequest; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
Uri url = request.getUrl();
if ("https://www.fengshihao.com/user.js".indexOf(url.toString()) == 0) {
final WebResourceResponse userjs = new WebResourceResponse("text/javascript", "UTF-8",
new ByteArrayInputStream("console.log('hello user js');".getBytes()));
return userjs;
}
return super.shouldInterceptRequest(view, request);
}
示例2: shouldInterceptRequest
import android.webkit.WebResourceRequest; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
if (request != null && request.getUrl() != null) {
try {
if (!GlobalConfig.isExcludeHost(request.getUrl().getHost())) {
return getResponseFromUrl(new URL(request.getUrl().toString()));
}
} catch (Throwable e) {
e.printStackTrace();
}
}
return null;
}
示例3: shouldInterceptRequest
import android.webkit.WebResourceRequest; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
String url = null != webResourceRequest.getUrl() ? webResourceRequest.getUrl().toString() : null;
if (!TextUtils.isEmpty(url) && url.startsWith(LOCAL_FILE_SCHEMA)) {
return getLocalResource(url);
}
if (null != _webViewDelegate && null != _webViewDelegate.get()) {
return _webViewDelegate.get().shouldInterceptRequest(webView, webResourceRequest);
}
return super.shouldInterceptRequest(webView, webResourceRequest);
}
示例4: shouldOverrideUrlLoading
import android.webkit.WebResourceRequest; //导入方法依赖的package包/类
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri url = request.getUrl();
if (url != null && url.toString().startsWith("htyridapp://")) {
Intent intent = new Intent();
intent.setData(Uri.parse(url.toString()));
startActivity(intent);
return true;
}
return super.shouldOverrideUrlLoading(view, request);
}
示例5: shouldOverrideUrlLoading
import android.webkit.WebResourceRequest; //导入方法依赖的package包/类
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (request.getUrl().getHost().length() == 0) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, request.getUrl());
view.getContext().startActivity(intent);
return true;
}
示例6: shouldOverrideUrlLoading
import android.webkit.WebResourceRequest; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
// Force links to be opened inside WebView and not in Default Browser
// Thanks http://stackoverflow.com/a/33681975/1815624
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri uri = request.getUrl();
if (uri.getScheme().equals("market")) {
Intent marketIntent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(marketIntent);
return true;
}
view.loadUrl(request.getUrl().toString());
return super.shouldOverrideUrlLoading(view, request);
}
示例7: shouldOverrideUrlLoading
import android.webkit.WebResourceRequest; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri link = request.getUrl();
return handleUri(link);
}
示例8: shouldInterceptRequest
import android.webkit.WebResourceRequest; //导入方法依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(final WebView view, final WebResourceRequest request) {
if (!blockingEnabled) {
return super.shouldInterceptRequest(view, request);
}
final Uri resourceUri = request.getUrl();
// shouldInterceptRequest() might be called _before_ onPageStarted or shouldOverrideUrlLoading
// are called (this happens when the webview is first shown). However we are notified of the URL
// via notifyCurrentURL in that case.
final String scheme = resourceUri.getScheme();
if (!request.isForMainFrame() &&
!scheme.equals("http") && !scheme.equals("https")) {
// Block any malformed non-http(s) URIs. WebView will already ignore things like market: URLs,
// but not in all cases (malformed market: URIs, such as market:://... will still end up here).
// (Note: data: URIs are automatically handled by WebView, and won't end up here either.)
// file:// URIs are disabled separately by setting WebSettings.setAllowFileAccess()
return new WebResourceResponse(null, null, null);
}
// WebView always requests a favicon, even though it won't be used anywhere. This check
// isn't able to block all favicons (some of them will be loaded using <link rel="shortcut icon">
// with a custom URL which we can't match or detect), but reduces the amount of unnecessary
// favicon loading that's performed.
final String path = resourceUri.getPath();
if (path != null && path.endsWith("/favicon.ico")) {
return new WebResourceResponse(null, null, null);
}
final UrlMatcher matcher = getMatcher(view.getContext());
// Don't block the main frame from being loaded. This also protects against cases where we
// open a link that redirects to another app (e.g. to the play store).
if ((!request.isForMainFrame()) &&
currentPageURL != null &&
matcher.matches(resourceUri, Uri.parse(currentPageURL))) {
// Bandaid for issue #26: currentPageUrl can still be null, and needs to be investigated further.
if (callback != null) {
callback.countBlockedTracker();
}
return new WebResourceResponse(null, null, null);
}
return super.shouldInterceptRequest(view, request);
}
示例9: shouldOverrideUrlLoading
import android.webkit.WebResourceRequest; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
final Uri uri = request.getUrl();
return handleUri(view, uri);
}