When the application is opened a webView opens say "www.google.com". If the user types in some query and presses Search(in the WebView itself, not an Android button) the next page loads. Now my need is to know if the webView has loaded the next page that is the search results for the query.
Is there any built-in method to check that?
EDIT 1
Implementing the method of Asuthosh Panda and Chintan Soni. It still doesn't work. This is implemented in a fragment. Does that affect the code in any way?
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
String url;
//String urrrl=null;
View view = inflater.inflate(R.layout.fragment_net_con, container, false);
myWebView = (WebView)view.findViewById(R.id.webView21);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("https://www.google.com");
myWebView.setWebViewClient(new WebViewClient());
url=myWebView.getUrl().toString();
Log.d("My app msg","I am here");
Log.d("URL ",url);
if(url.contains("q=")){
System.exit(1);
}
activityCommander.setwebs(myWebView.getUrl());
return view; }
By doing so, whenever a cookie is set by the API through the API call using the particular instance of okHttpClient , the cookie will be stored automatically and will be used by Webview launched by the App.
Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.
WebView in Android is a wrapper around the WebKit rendering engine, and can be used to display web pages inside your application. As a developer, you can use this control to render any web page as part of your application. These pages can be local or can be consumed from the Web.
You can set a callback with WebViewClient
as below:
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do your stuff here
}
});
I don't know what are you asking really
So, I am sharing my Simple Browser Project code
Hoping it will Help you
First,you need to define a WebView Client Class
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebClient extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
Secondly edit Activity main like this
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendGo(View view) {
Intent intent = new Intent(this,GoActivity.class);
startActivity(intent);
}
}
Thirdly GGoActivity like this
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class GoActivity extends Activity {
WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_go);
myWebView = (WebView) findViewById(R.id.webview_go);
myWebView.loadUrl("http://www.google.com");
myWebView.setWebViewClient(new MyWebClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
}
Happy Coding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With