Hello Guys,
Today I am going to explain select browser for display any url into web.
Its a simple thing to implement into your android app.
Just see the sample code.
NOTE: Run this app into your device for see the proper output.
Sample Code:
Permission: Internet permission is required in your manifest file.
<uses-permission android:name="android.permission.INTERNET"/>
File: activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
File: MainActivity.java
package com.sneha.choosebrowserdemo;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webView1);
WebViewClient viewClient = new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
startActivity(intent);
view.loadUrl(url);
return true;
}
};
webView.setWebViewClient(viewClient);
webView.loadUrl("http://www.google.com");
}
}
Output:
Happy Coding...!!!
Today I am going to explain select browser for display any url into web.
Its a simple thing to implement into your android app.
Just see the sample code.
NOTE: Run this app into your device for see the proper output.
Sample Code:
Permission: Internet permission is required in your manifest file.
<uses-permission android:name="android.permission.INTERNET"/>
File: activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
File: MainActivity.java
package com.sneha.choosebrowserdemo;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webView1);
WebViewClient viewClient = new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
startActivity(intent);
view.loadUrl(url);
return true;
}
};
webView.setWebViewClient(viewClient);
webView.loadUrl("http://www.google.com");
}
}
Output:
Happy Coding...!!!
No comments:
Post a Comment