Tuesday, March 20, 2012

[android-developers] hi

Hi All
I need help on reading the html source of a page in android
i am able to load the html link in webview
and able to read html source but my problem is
while i am reading the html source of my page
i am unable to get access token and user id 
i am unable to find where i am going wrong
following is my code
please help me


public class InstagramAlbumsActivity extends Activity {
    String url = "http://ncpo.cc/test/example.php";
       Button login;
    org.apache.http.HttpResponse response;
    WebView mWebView;
    String s;

    String html = "";

    String line = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.openingwebpage);
        mWebView = (WebView) findViewById(R.id.webView1);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.clearCache(true);
        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.setWebViewClient(new HelloWebViewClient());
        mWebView.loadUrl(url);
    }

    final class HelloWebViewClient extends WebViewClient {

        @Override
        public void onPageFinished(WebView view, String url) {
            String s = mWebView.getUrl();
            Log.d("HelloWebViewClient   url ", s);

            try {

                HttpClient client = new DefaultHttpClient();
                HttpGet request = new HttpGet(s);

                response = client.execute(request);

                java.io.InputStream in = response.getEntity().getContent();
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(in));
                StringBuilder str = new StringBuilder();
                Log.d("ddfhfghg   url ",
                        "in String Builder" + mWebView.getUrl());
                while ((line = reader.readLine()) != null) {

                    str.append(line);
                    html = str.toString();
                    if (html.contains("<!DOCTYPE html PUBLIC ")) {
                        Log.d("ddfhfghg   url ", "in while" + mWebView.getUrl());
                        Log.d("html in if", html);

                    } else if (html.contains("Popular Media")) {
                        mWebView.loadUrl(url);
                    } else {
                        Log.d("html in the else begining", html);

                    }

                }
                Log.d("ddfhfghg   url ", "after while" + mWebView.getUrl());
                in.close();

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub
            return false;
        }
    }

}


Please help me

Thanks
Swathi.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment