Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,
I wont to create a simple android app. The thing is if i open the application then in the start up the application should open the URL like www.google.com with in the application only not in a any default browser by using like web view control. So please provide me a code
Thanks in advance and i hope i will get good result
Posted
Updated 12-Sep-17 16:49pm
Comments
Member 12785618 10-Oct-16 9:02am    
if i getting the url of any content like pdf,document .etc from the webservice. then how i display the pdf in my android app without going out from the app or dint want to use the 3rd party app.

Web view control is generally used to open any URL within your application. Therefore you don't have to move to the other application like inbuilt browser, or chrome etc.

As per the Documentation :
If you want to deliver a web application (or just a web page) as a part of a client application, you can do it using WebView.

See the example,
layout :
HTML
<webview xmlns:android="http://schemas.android.com/apk/res/android">
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</webview>

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

and last Manifest:
HTML
<manifest ...="">
    <uses-permission android:name="android.permission.INTERNET" xmlns:android="#unknown" />
    ...
</manifest>

You can look at the example[^] as well. :)

-KR
 
Share this answer
 
v2
Comments
Hareesh Malli 7-Mar-14 9:29am    
Can i perform all operations like log in, register, edit and update on website with in the application.
Krunal Rohit 7-Mar-14 9:33am    
If webview able to open up a browser, there you go. :)
Give it a try.

-KR
Hareesh Malli 7-Mar-14 9:37am    
No i don't wont to open any browser for operation in website. Means page navigation also should done with in the application so is it possible
Krunal Rohit 7-Mar-14 9:38am    
Have you tried the example ??
-KR
Hareesh Malli 8-Mar-14 2:09am    
No it's not working friend. it directly opens the browser for loading website. Website is not run with in the application. What can i do now friend
code for main.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="match_parent"
android:layout_height="match_parent">
<webview xmlns:android="http://schemas.android.com/apk/res/android">
    android:id="@+id/wvBrowser"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

</webview></linearlayout>


And code for mainactivity.java


public class MainActivity extends ActionBarActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.home);

      WebView ourBrow=(WebView) findViewById(R.id.wvBrowser);
      ourBrow.getSettings().setJavaScriptEnabled(true);
      ourBrow.getSettings().setLoadWithOverviewMode(true);
      ourBrow.getSettings().setUseWideViewPort(true);
      ourBrow.setWebViewClient(new ourViewClient());
      ourBrow.loadUrl("http://www.google.com");
     }
  }



And after create a " ourViewClient.java " class and copy the below code on ourViewClient.java

package com.example.app;

import android.webkit.WebView;
import android.webkit.WebViewClient;


public class ourViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView v, String url)
    {
        v.loadUrl(url);
        return true;
    }
}



That's it and enjoy.
Now your app can run any website like YouTube or JavaScript webpages with in your app. And it don't open any browsers for loading webpages.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900