0

I'm creating an app that needs to be able to go onto certain websites in order to inject javascript onto those websites. However, the website that I need to access does not load when I try to. This is my activity's code

import android.content.SharedPreferences;
import android.media.audiofx.BassBoost;
import android.preference.PreferenceManager;
import android.support.v4.content.SharedPreferencesCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ConvergintActivity extends AppCompatActivity {

    WebView webView;

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

        webView = (WebView) findViewById(R.id.convergintWebView);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.clearSslPreferences();
        webView.loadUrl("https://infoshare.convergint.com/login.php");
        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                // do your stuff here
                SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                String username = sharedPrefs.getString("convergintUsername", "");
                Log.e("Debug!", "Username = "+ username);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)        
            {
                view.loadUrl(url);
                return true;
             }
        });
    }
}

The webpage I'm trying to load is https://infoshare.convergint.com/login.php. Why will www.google.com load but infoshare.convergint.com/login.php won't? How can I fix this problem?

BWieder
  • 33
  • 6

1 Answers1

0

Are you trying to load the page in your webview? You should set shouldOverrideUrlLoading() to return false.

However,you could add this settings and,

webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

To check error response in Webview, add this in your WebViewClient method

@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error){
                        //do something here
}
eztephen
  • 38
  • 5
  • 1
    I did exactly as you said, but I'm still just getting a white screen. I checked the Logcat and see that I'm getting "Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found." Do you know how I can fix this? @eztephen – BWieder Jul 19 '16 at 11:36