如何在webview android studio中替换url? [英] how to replace url in webview android studio?
本文介绍了如何在webview android studio中替换url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我首先知道 URL 包含广告,然后我想将广告替换为如何将广告替换为 as.
i am getting first that URL contain ad then i want to replace ad with as how to replace ad with as.
@Override
protected void onStart() {
super.onStart();
Intent intent = getIntent();
Uri data = intent.getData();
//want to check contains in data and if contains i want to replace it
if(data.toString().contains("ad")){
data.toString() = data.toString().replace("ad", "xyz");
}
try {
webView.loadUrl(data.toString());
}
catch (Exception e){
e.printStackTrace();
}
}
推荐答案
可能对你有帮助的方法在下面,你应该放入@override方法
The method that may help you is below which you should put into the @override method
String myUrl = url;
myUrl = myUrl.replace("ad", as);
然后在任何地方使用新字符串.您无法更改原始网址 :)
Then use the new string wherever you want . You can't change the original url :)
方法替换返回字符串值,如 API DOC 所述
The Method replace returns the string value as API DOC says
public String replace (CharSequence target, CharSequence replacement)
尝试这样做:
@Override
protected void onStart() {
super.onStart();
Intent intent = getIntent();
Uri data = intent.getData();
String mString;
//want to check contains in data and if contains i want to replace it
if(data.toString().contains("ad")){
mString = data.toString().replace("ad", "xyz");
}
try {
webView.loadUrl(mString);
}
catch (Exception e){
e.printStackTrace();
}
}
这篇关于如何在webview android studio中替换url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文