- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
虽然这个问题已被问过多次,但真正与我的问题相关的唯一问题是这个 ( Can I use shouldInterceptRequest to block a particular call in Android? ),但它在 3 年多前被问过,最终没有得到任何答复。
我要阻止的请求是 POST 请求,因此 shouldOverrideUrlLoading 方法无法拦截它。
单击按钮后,webview 加载包含以下字符串的 URL:“androidBundleId_********”。
我需要阻止此请求并将用户重定向到 Play 商店(但我知道该怎么做!)
问题是 shouldInterceptRequest 方法的返回类型是 WebResourceResponse (哦,我多么希望它是 bool 值!)。因此,我必须至少返回一个空白的 WebResourceResponse。
我不想这样做,因为 WebResourceResponse 中的所有内容都会加载到我的应用程序中。我只希望 webview 拦截请求并阻止它。
应用程序应始终显示相同的网页,不应加载任何数据,Play 商店 intent 除外。
我只发布我的代码的相关部分。
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if(url.contains("androidBundleId_")){
String bundleID = url.substring(url.indexOf("androidBundleId_")+"androidBundleId".length()+1, url.length());
try {
getContext().startActivity(new Intent
(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + bundleID)));
} catch (android.content.ActivityNotFoundException anfe) {
getContext().startActivity(new Intent
(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + bundleID)));
}
// I'D LIKE TO RETURN NOTHING HERE !!!
}
return super.shouldInterceptRequest(view, url);
}
我知道这个签名已被弃用,但我正在使用 minSdk 16 构建一个应用程序,因此我只能使用这个而不是接受请求作为第二个参数的那个。
你有什么解决办法吗?请注意,我无法更改包含该按钮的网页。
最佳答案
由于没有机会做我一直要求的事情,我们更改了整个应用程序逻辑并最终切换到 WebChromeClient。它自动处理链接/Intent
关于android - 使用 shouldInterceptRequest 阻止数据加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42387313/
我有 webView 覆盖了 shouldInterceptRequest 方法: @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override
我想创建一个 Intranet 应用程序。这个应用程序将显示内容,通常只能在我们的内部环境中访问。例如http://intranet.ourfirm.com 现在我们可以从外部访问此内容例如https
我想拦截 WebViewClient 中的所有 HTTP 请求并发出我自己的请求。我遇到的问题是处理压缩响应。 有几个不同的帖子建议可行的方法(例如 AndroidHttpClient.getUngz
虽然这个问题已被问过多次,但真正与我的问题相关的唯一问题是这个 ( Can I use shouldInterceptRequest to block a particular call in And
我正在尝试集成一个 javascript 插件,该插件通过使用 XmlHttpRequest 调用来加载一些资源。我希望此脚本在 WebView 的本地加载页面中运行。正如您可能已经猜到的那样,Xml
我正在尝试拦截并停止加载 webView 上的所有 mp4 视频,因为我正在使用 shouldInterceptRequest。我能够拦截视频,例如:显示一个对话框,但是我无法停止加载它们,知道为什么
我想在特定时间缓存 WebView 中显示的图像,例如7 天,所以我需要将图像缓存保存到磁盘并从磁盘加载它们并将它们提供给 WebView。 我还需要调整图像的大小以避免 WebView;内存使用率高
我在 Android WebView 上玩得很开心。 我用它来显示登录屏幕,然后在响应时拦截授权代码。应该很简单... 如果我只覆盖 shouldOverrideUrlLoading 但如果我覆盖(就
请告诉我方法 public WebResourceResponse shouldInterceptRequest (WebView view, WebResourceRequest request)
我在 Android (KitKat) 上使用 WevView,我正在尝试覆盖 shouldInterceptRequest() 并发出我自己的 HTTP 请求 - 让我的应用而不是 webview
我使用了下面的代码 public WebResourceResponse shouldInterceptRequest(WebView view, String url) { alertsav
我正在尝试拦截来自 WebView 的请求,以便我可以注入(inject)额外的 header 。我正在将 WebViewClient 应用于 WebView 并覆盖 shouldInterceptR
在 API21 中,Google 修改了 shouldInterceptRequest 方法以使用 WebResourceRequest 请求 而不是 String url。有什么方法可以编写一个扩展
目标: 覆盖 WebView 发出的所有请求并自己发出请求(最终设置代理)。 代码: @Override public WebResourceResponse shouldInterceptReque
我正在使用 Xamarin 开发一个混合 Android 应用程序,但遇到了问题。我正在使用 webview 和自定义路由引擎来服务器 Razor 页面。这一切都工作正常。我的问题是 jQuery g
我在 android 中使用 webview 创建了一个网络浏览器。我的目标是在加载之前控制 webview 的内容。每当 webview 的内容向任何域服务器发出请求时,它都必须通过 shoulIn
我的 Android 应用程序在 WebView 中显示 html5 电子书。 我有一个压缩文件,其中包含一本电子书及其所有资源:文本、图像和音频(mp3 文件)。 为了解压本书,我使用了 shoul
我有一个应用程序在 Android WebViewClient 的 shouldInterceptRequest(WebView view, String url) 和 shouldOverrideU
我正在使用 shouldInterceptRequest 拦截来自 webview 的请求 下面是我返回 WebResourceResponse 的代码 @TargetApi(Build.VERSIO
我想在 webview 中为请求添加自定义 header 。我认为应该可以在 shouldInterceptRequest 中完成。因为我的最低 API 级别低于 21 shouldIntercept
我是一名优秀的程序员,十分优秀!