0

I want to know how to show a page only with some parts of a HTML code. Something like login and password box, login button... Is it possible to do this using only WebView?

My code:

MainActivity.java:

public class MainActivity extends ActionBarActivity {

Button enterButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final WebView myWebView = (WebView) findViewById(R.id.webView1);

WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

myWebView.setWebViewClient(new WebViewClient());

myWebView.loadUrl("http://siga.ufvjm.edu.br");

enterButton = (Button) findViewById(R.id.enterButton);
}


private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (Uri.parse(url).getHost().equals("http://siga.ufvjm.edu.br")) {
        // This is my web site, so do not override; let my WebView load the page
        return false;
    }
    // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
    return true;
}
}
Marlon Paranhos
  • 101
  • 1
  • 2
  • What part of the code isn't working? You don't need to post your entire code, GUI and all - just post the failing section. –  Nov 03 '14 at 00:20
  • There's no failing section. My doubt is: How to show only the HTML part that I want? How to edit and put it to work in my app. In other words, I wanna load the HTML page, but show only the "user", "password" boxes and "login" button. Thanks. – Marlon Paranhos Nov 03 '14 at 00:36
  • I have never done this, so I do not know how to solve your problem. As a restatement of my previous comment, you should just post the minimum code of attempt to solve the problem and not your entire working solution. I hope someone helps you soon! –  Nov 03 '14 at 01:22

1 Answers1

1

Try to load your page with HttpClient: https://stackoverflow.com/a/4457526/3864698

After that you can customize your html code and set to WebView with loadDataWithBaseURL.

Community
  • 1
  • 1
QArea
  • 4,955
  • 1
  • 12
  • 22