0

I have responsive webpage. I want to have an android application, that open this webpage. So after i clicked on icon of application, it shows me menu and when i click on some button it shows me website inside this application. It is possible? If yes, how?

I tied only something like that:

    WebView webview = new WebView(this);
    setContentView(webview);

But it is not good for me... because it is only link to open it via browser... So finally I need something like mobile browser. I dont know if it is possible for me. Maybe you give me some more advices.

5 Answers5

0

In your xml file add this code:

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

and In your activity:

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("http://www.google.com");

}
joselufo
  • 3,393
  • 3
  • 23
  • 37
0

From your main activity, call startActivity so that Activity2 is started. For Activity2, call setContentView(R.layout.webview). In Activity2 onCreate() method, use WebView.loadURL(url).

You can configure settings via: WebView.getSettings().xxx();

xxx can be setBuiltInZoomControls(), SetJavaScriptEnabled, setDatabaseEnabled, or more.

webgenius
  • 856
  • 3
  • 13
  • 30
0

Firstly create a fresh XML file like this ..

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

Now Create a new class for webView like this ...

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class ReviewView extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_view); // your xml file created above 

        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("https://play.google.com/store?utm_source=SEM&utm_campaign=Evergreen&pcampaignid=MKTADIN2771401PYBKWSTXHYSEM");

    }

} 

That's it .. you are good to go

AndroidHacker
  • 3,596
  • 1
  • 25
  • 45
0
    webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("www.yoursite.com");

   // you need to setWebViewClient for forcefully open in your webview 
    webview.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
MilapTank
  • 9,988
  • 7
  • 38
  • 53
0

Let's sum up the answers:

-First, your application MUST have permission to access internet. You can do it by using this code block in your projects "AndroidManifest.xml" file:

<uses-permission android:name="android.permission.INTERNET" />

Put this code block in manifest tag, not in application tag. Like this:

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="20" />

<!-- Permission here -->
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:name="....

-Second, you must design a UI in xml which contains a WebView widget. Codes in other answers show you how to do it properly:

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

This is xml code of a webview inside your layout file. After you implement a webView to your layout.

-Last, follow code TeRRo gave, you can use it to show whatever page you want to load by changing web adress he wrote as example. Reposting it here:

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);

webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");

}
Community
  • 1
  • 1
Mel
  • 1,730
  • 17
  • 33
  • When I have website in my app. How can I solve problem with hyperlinks? How to make it to open in this app? – Thomas Edifice Jul 04 '14 at 11:32
  • This is not a full code, it won't work if you just copy paste what you see here. You must add required codes to your projects manifest, layout xml and java class. After that, just change "http://www.google.com" with your link. – Mel Jul 04 '14 at 11:35
  • ok I understand. Everything is ok, but when finnaly app load my website and i click on some link on website it is again the same... that it shows me: complete action using... – Thomas Edifice Jul 04 '14 at 11:39
  • i need maybe something like... OverrideUrlLoading – Thomas Edifice Jul 04 '14 at 11:39
  • Yes, see this answer here : http://stackoverflow.com/questions/2378800/clicking-urls-opens-default-browser – Mel Jul 04 '14 at 11:43
  • yes this is very good thank you... if I can I will give green tick (correct answer) to you too, but I can tick only one answer... hmmm – Thomas Edifice Jul 04 '14 at 11:54