Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a webpage in an Android App [closed]

I was wondering what you guys/gals would recommend in terms of opening a webpage inside an app (i.e a smaller window with a webpage open in it but not a web browser) Im trying to integrate my webpage into my app more or less. Thanks :)

like image 961
Chris Avatar asked Sep 02 '13 23:09

Chris


People also ask

How do I view Web pages on Android?

String url = "http://www.example.com"; Intent i = new Intent(Intent. ACTION_VIEW); i. setData(Uri. parse(url)); startActivity(i);


2 Answers

Have you tried using the WebView layout?

In your layout file:

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

Include the INTERNET permission into your manifest:

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

And then in your Activity:

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

This will embed a web-browser into your application (rather than open an external browser).

like image 160
matthewrdev Avatar answered Sep 28 '22 01:09

matthewrdev


You can place you view group and then place the webview inside and modify size as needed

<LinearLayout
    android:orientation="vertical"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
 <WebView
         android:id="@+id/webView"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">

 </WebView>
</LinearLayout>

In your manifest file give the permission

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

then you get the object from code

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.google.com");
like image 33
Ranjithkumar Avatar answered Sep 27 '22 23:09

Ranjithkumar