Android Tutorial: Wrapping a Mobile Website with WebView
It may not be the most exciting App, but my first App in the Google Play store wraps a mobile real estate website. My App is no longer in the Google Play store, but you can view a photo of the end product at the bottom of this page
The following code demonstrates a simple way to wrap a website for exposure in the Play store.
MainActivity.java
package com.himebaugh.webviewwrap; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.webkit.GeolocationPermissions; import android.webkit.WebChromeClient; import android.webkit.WebView; @SuppressLint("SetJavaScriptEnabled") public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView browser = (WebView) findViewById(R.id.webView1); browser.getSettings().setJavaScriptEnabled(true); browser.getSettings().setGeolocationEnabled(true); browser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); browser.getSettings().setBuiltInZoomControls(true); browser.getSettings().setDomStorageEnabled(true); browser.setWebChromeClient(new WebChromeClient() { public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } }); browser.loadUrl("http://cptmrkschmdt.wordpress.com/"); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
activity_main.xml (in res/layout)
<?xml version="1.0" encoding="UTF-8"?> <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" tools:context=".MainActivity"> <WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" /> </RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.himebaugh.webviewwrap" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_GPS" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.himebaugh.webviewwrap.MainActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:label="@string/app_name" android:screenOrientation="portrait" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
Screenshot of the application
Category: Android Application Development
The apllication opens in browser… not in webview…
What am I doing wrong?