Web Browsing - Changing the source of a page before showing a website?

I have a website. The website has the text "pic." When I first display a website in Webview, I can change the text to "PicGreat". It works!

But later, when the user clicks the link (somewhere on the website), I redirect the user to a new HTML website. Before I show the site, I want to change the text "Pic" to "PicGreat".

How can i do this? Should I write a function and then call the function in "public boolean shouldOverrideUrlLoading"?

I found a similar question here in Stackoverflow, but didn't solve it. how to set up web browsing client

main.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/webview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
/>

AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

WebTest.java

public class WebTestActivity extends Activity {

 WebView mWebView;
 String rline = "";

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 setContentView(R.layout.main);

 mWebView = (WebView) findViewById(R.id.webview);
 mWebView.getSettings().setJavaScriptEnabled(true);

 HttpURLConnection urlConnection = null;
 try
 {
 URL url = new URL("http://www.picSite.com/");
 urlConnection = (HttpURLConnection) url.openConnection();
 InputStream in = new BufferedInputStream(urlConnection.getInputStream());
 BufferedReader rd = new BufferedReader(new InputStreamReader(in), 4096);
 String line;

 while ((line = rd.readLine()) != null) {
 rline += line+"\n";
 }
 rd.close();

 } catch (MalformedURLException e) {
 e.printStackTrace();
 } catch (IOException e) {
 e.printStackTrace();
 } finally {
 if ( null != urlConnection )
 {
 urlConnection.disconnect();
 }
 }

 String getNewCode = rline.replace("Pic", "PicGreat");

 mWebView.loadData(getNewCode, "text/html", "utf-8");

 mWebView.setWebViewClient(new HelloWebViewClient());
 }

 private class HelloWebViewClient extends WebViewClient {
 @Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) {
 view.loadUrl(url);
 return true;
 }

 }
}
+5
source share
1

WebViewClient.shouldInterceptRequest():

- . null, WebView , . .

. , , .

+1

All Articles