Reputation: 3
I first check that the Uri data contains ad, and 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.contains("ad")){
data.replace("ad", "as");
}
try {
webView.loadUrl(data.toString());
}
catch (Exception e){
e.printStackTrace();
}
}
Upvotes: 0
Views: 85
Reputation: 12953
Uri does not have contains
and replace
, so you have to convert to String
first.
Try this:
if (data != null) {
String uriString = data.toString();
if (uriString.contains("ad")) {
uriString = uriString.replace("ad", "as");
}
try {
webView.loadUrl(uriString);
}
catch (Exception e){
e.printStackTrace();
}
}
Upvotes: 1