Skip to content Skip to sidebar Skip to footer

Open A Url Without Help Of Android Browser In Android?

I am developing an android application in which I want to fetch the news from a url without opening default browser of android. This means I want to fetch only the texutal content

Solution 1:

If I understand correctly - you need to make a request online and receive in return the html code. This is done as follows:

DefaultHttpClientclient=newDefaultHttpClient();
HttpGetrequest=newHttpGet();
request.setURI(newURI(http://example.com/news));HttpResponseresponse= client.execute(request);
BufferedReaderin=newBufferedReader(newInputStreamReader(
response.getEntity().getContent()));
StringBuffersb=newStringBuffer("");
String line;
while ((line = in.readLine()) != null) {
    sb.append(line);
}
in.close();

Stringhtml= sb.toString();

Solution 2:

Do you mean that you want to parse the actual content of the webpage to your application? When I did so in one of my apps, I parsed the whole webpage with a simple http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html and then I took out those tags which where relevant. This however requires some pretty heavy dynamical programming running under an asynctask (http://developer.android.com/reference/android/os/AsyncTask.html).

URLurl=newURL(XML_INIT_ADRESS);
XmlPullParserFactoryfactory= XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParserxpp= factory.newPullParser();
xpp.setInput(url.openStream(), null);

I'm personally not very experienced with Android yet and I'm still learning but you should be able to parse the news from a webpage this way.

Edit: This approach pretty much requires some kind of identification of the certain "news-tags", Antons answer is better if they are "undefinable".

Solution 3:

HiYesYou can implement this.UseThis code which i mention below.



 - WebView webView = (WebView) findViewById(R.id.webview_btn);
   WebSettings settings = webView.getSettings();
   mProgress = ProgressDialog.show(this, "Loading", "Please wait for a moment...");

               settings.setJavaScriptEnabled(true);
               settings.setSupportZoom(true);
               settings.setBuiltInZoomControls(true);

               WebViewClient client = newWebViewClient() {
                @OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
                    // TODO Auto-generated method stub
                    view.loadUrl(url);
                    mProgress.show();

                    returntrue;
                }
                   @OverridepublicvoidonPageFinished(WebView view, String url) {

                    if(mProgress.isShowing())
                    {
                        mProgress.dismiss();
                    }
                   }
               };
               webView.loadUrl(enter your url);
               webView.setWebViewClient(client);

Solution 4:

HttpClienthttpClient=newDefaultHttpClient();
HttpContextlocalContext=newBasicHttpContext();
HttpGethttpGet=newHttpGet("http://www.example.com/" + URL);
response = httpClient.execute(httpGet, localContext);

Post a Comment for "Open A Url Without Help Of Android Browser In Android?"