0

I do implemented few applications, that can open the URL/Web Link through Web browser.

Just goggling to find if there is any way or approach to

Open the URL Link straight with in the app, without launch it in web browser, but i couldn't find the exact answer...

Does anyone has any idea friends??

4 Answers 4

2

All you need is a WebView see that tutorial

Layout Code :

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" >

  <TextView
  android:id="@+id/textView1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/hello_world" />

  <EditText
  android:id="@+id/urlField"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignTop="@+id/textView1"
  android:layout_centerHorizontal="true"
  android:ems="10" />

  <Button
  android:id="@+id/button1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@+id/urlField"
  android:layout_centerHorizontal="true"
  android:onClick="open"
  android:text="@string/browse" />

   <WebView
  android:id="@+id/webView1"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@+id/textView1"
  android:layout_alignParentBottom="true"
  android:layout_below="@+id/button1" />
   </RelativeLayout>

Java Code :

   package com.example.webview;

   import android.os.Bundle;
   import android.app.Activity;
   import android.view.Menu;
   import android.view.View;
   import android.view.Window;
   import android.webkit.WebSettings;
   import android.webkit.WebView;
   import android.webkit.WebViewClient;
   import android.widget.EditText;
   import android.widget.TextView;

   public class MainActivity extends Activity {

   private EditText field;
   private WebView browser;

  @Override     
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  field = (EditText)findViewById(R.id.urlField);
  browser = (WebView)findViewById(R.id.webView1);
  browser.setWebViewClient(new MyBrowser());
  }
  public void open(View view){
  String url = field.getText().toString();
  browser.getSettings().setLoadsImagesAutomatically(true);
  browser.getSettings().setJavaScriptEnabled(true);
  browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  browser.loadUrl(url);
  }
  private class MyBrowser extends WebViewClient {
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
     view.loadUrl(url);
     return true;
  }
  }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   // Inflate the menu; this adds items to the action bar if it is present.
   getMenuInflater().inflate(R.menu.main, menu);
   return true;
}

}

manifest File :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.webview"
android:versionCode="1"
android:versionName="1.0" >

 <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
  <uses-permission android:name="android.permission.INTERNET"/>

  <application
     android:allowBackup="true"
     android:icon="@drawable/ic_launcher"
     android:label="@string/app_name"
     android:theme="@style/AppTheme" >
     <activity
     android:name="com.example.webview.MainActivity"
     android:label="@string/app_name" >
     <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
   </application>

   </manifest>
Sign up to request clarification or add additional context in comments.

Comments

0

Have you heard about WebView? Using webview you can create your own browser in your app. Just google "Webview", you will get many good examples for this.

Comments

0

You could use a Webview class if you want a view want to shown or you could use Rest/Post webservices with HttpUrlConnection/Androidhttpclient classes if you are interested in data part and dont want a view to be shown

Comments

0

Use the code:

WebView varWebView = (WebView) findViewById(R.id.webview);
varWebView.loadUrl("http://www.example.com");

also you can pass custom HTML to webview using loadData() as below:

String strCustomHtml = "<html><head></head><body>Hello, World!</body></html>";
varWebView.loadData(strCustomHtml, "text/html", "UTF-8");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.