0

Hi I am creating an app that loads a url. it works fine but when I try to load vine.co it does not show any data.works like loadin.......... I am confuse what I am missing here. See My Code . website Url: http://likesplusmore.com/html/

android code is:

public class MainActivity extends Activity {

private WebView wv;
private WebView wv1;
//private String url = "http://www.m.morefreefollowers.filebanks.info/html";
private String url = "http://www.likesplusmore.com/html";

private String mUrl;
private String fbUrl;
private CountDownTimer countDownTimer;
private final long startTime = 60 * 1000;
private final long interval = 1 * 1000;
private boolean timerHasStarted = false;
private Button btn_back;
private Button btn_refresh;
private RelativeLayout rlBtn;
private String currentUrl;
private ArrayList<String> domainList;

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

    countDownTimer = new MyCountDownTimer(startTime, interval);
    wv = (WebView) findViewById(R.id.wv_content);
    wv1 = (WebView) findViewById(R.id.wv_content1);
    btn_back = (Button) findViewById(R.id.btn_back);
    btn_refresh = (Button) findViewById(R.id.btn_refresh);
    rlBtn = (RelativeLayout) findViewById(R.id.lnBtn);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setLoadWithOverviewMode(true);
    wv.getSettings().setUseWideViewPort(true);
    wv.getSettings().setBuiltInZoomControls(true);
    wv.getSettings().setPluginState(PluginState.ON);
    wv.getSettings().setSupportMultipleWindows(false);
    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    wv.setWebViewClient(new myWebClient());
    wv.loadUrl(url);
    wv1.getSettings().setJavaScriptEnabled(true);
    wv1.getSettings().setLoadWithOverviewMode(true);
    wv1.getSettings().setUseWideViewPort(true);
    wv1.getSettings().setBuiltInZoomControls(true);
    wv1.getSettings().setPluginState(PluginState.ON);
    wv1.getSettings().setSupportMultipleWindows(false);
    wv1.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    wv1.setWebViewClient(new myWebClient1());
    AddDomainList();
    OnClick();
}
//add more domain
private void AddDomainList() {
    domainList=new ArrayList<String>();
    domainList.add("www.facebook.com");
    domainList.add("www.facebook.vn");
    domainList.add("facebook.com");
    domainList.add("facebook.vn");
    domainList.add("youtube.com");
    domainList.add("www.youtube.com");
    domainList.add("twitter.com");
    domainList.add("www.twitter.com");
    domainList.add("soundcloud.com");
    domainList.add("www.soundcloud.com");
    domainList.add("www.pinterest.com");
    domainList.add("pinterest.com");
    domainList.add("instagram.com");
    domainList.add("www.instagram.com");
    domainList.add("linkedin.com");
    domainList.add("vine.co");
    domainList.add("www.google.com.vn");
    domainList.add("plus.google.com");
    domainList.add("www.vine.co");

}

private boolean ContainDomain(String url)
{
    boolean contain=false;
    for(int i=0;i<domainList.size();i++)
    {
        if(url.contains(domainList.get(i)))
        {
            contain=true;
            break;
        }
    }
    return contain;
}
private void OnClick() {
    btn_back.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            BackEvent();
        }
    });
    btn_refresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (wv1.getVisibility() == View.VISIBLE) {
                wv1.loadUrl(currentUrl);
            }

        }
    });
}

public class myWebClient extends WebViewClient {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (ContainDomain(url)) {
            wv1.setVisibility(View.VISIBLE);
            rlBtn.setVisibility(View.VISIBLE);
            wv1.loadUrl(url);
            if (timerHasStarted == false) {
                countDownTimer.start();
                timerHasStarted = true;
            }
            CallWebApi caller = new CallWebApi();
            //caller.execute("http://m.morefreefollowers.filebanks.info/ws/actionfirstfblike.php?url="+ url);
            caller.execute(url);

            wv.setVisibility(View.GONE);
            wv.loadUrl("about:blank");
            fbUrl = url;
        } else {
            wv1.loadUrl("about:blank");
            wv1.setVisibility(View.GONE);
            rlBtn.setVisibility(View.GONE);
            wv.setVisibility(View.VISIBLE);
            wv.loadUrl(url);
            mUrl = url;
        }
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);
    }
}

public class myWebClient1 extends WebViewClient {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
    }

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

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);

    }
}

@Override
public void onBackPressed() {
    BackEvent();
}

private void BackEvent() {
    if (wv1.getVisibility() == View.VISIBLE) {
        CallWebApi caller = new CallWebApi();
        //caller.execute("http://m.morefreefollowers.filebanks.info/ws/actionfblike.php?url="+ fbUrl);
        caller.execute(fbUrl);

        wv1.loadUrl("about:blank");
        wv1.setVisibility(View.GONE);
        rlBtn.setVisibility(View.GONE);
        wv.setVisibility(View.VISIBLE);
        wv.loadUrl(mUrl);
        if (timerHasStarted == true) {
            countDownTimer.cancel();
            timerHasStarted = false;
        }

    } else {
        finish();
    }
}

public class CallWebApi extends AsyncTask<String, Void, Void> {

    @Override
    protected Void doInBackground(String... params) {
        String url = params[0];
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(url);
        post.setHeader("Accept-Charset", "utf-8");
        post.setHeader("Accept",
                "text/xml,application/text+xml,application/soap+xml");
        HttpResponse response = null;
        String responseBody = "";
        try {
            response = client.execute(post);
            responseBody = EntityUtils.toString(response.getEntity(),
                    "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (response != null) {
            Log.i("VALUE", responseBody);
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
    }

}

public class MyCountDownTimer extends CountDownTimer {
    public MyCountDownTimer(long startTime, long interval) {
        super(startTime, interval);
    }

    @Override
    public void onFinish() {
        if (wv1.getVisibility() == View.VISIBLE) { 
            if (timerHasStarted == true) {
                countDownTimer.cancel();
                timerHasStarted = false;
            }
            CallWebApi caller = new CallWebApi();
            //caller.execute("http://m.morefreefollowers.filebanks.info/ws/actionfblike.php?url="+ fbUrl);
            caller.execute(fbUrl);
            wv1.loadUrl("about:blank");
            wv1.setVisibility(View.GONE);
            rlBtn.setVisibility(View.GONE);
            wv.setVisibility(View.VISIBLE);
            wv.loadUrl(mUrl);

        } else {
            if (timerHasStarted == true) {
                countDownTimer.cancel();
                timerHasStarted = false;
            }
        }
    }

    @Override
    public void onTick(long millisUntilFinished) {
    }
}

}

I have Enabled java script etc. it load all pages fine. but creating problem in vine.co. can any body tell me what m i missing. works fine in website. thanks

Nadeem Yousaf
  • 563
  • 10
  • 31
  • I think this will help: http://stackoverflow.com/questions/7416096/android-webview-not-loading-https-url – Harry Jan 29 '15 at 03:57

1 Answers1

0

vine.co is https protocol.

Please find google search for "webview https"

or

Add this overriding method to your WebViewClient implementation. You'll need to compile it with Android SDK 2.2 (API level 8) or later. The method appears in the public SDK as of 2.2 (API level 8) but we've tested it on devices running 2.1, 1.6 and 1.5 and it works on those devices too (so obviously the behaviour has been there all along).

@Override

public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

handler.proceed(); // Ignore SSL certificate errors

}