Reputation: 83
I tried to create an app where it should open my webapp on localhost. I used webapp, but instead of showing up as an app, it asked me to choose internet browser. What should I do? Here's the code.
activity_main.xml
<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=".WebView" >
<WebView
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
MainActivity.java
package com.example.suryaagung;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Bundle;
import android.webkit.WebView;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//No title bar is set for the activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
//Full screen is set for the Window
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
final WebView SuryaAgung = (WebView)findViewById(R.id.main);
SuryaAgung.loadUrl("http://localhost:8080/app");
SuryaAgung.getSettings().setJavaScriptEnabled(true);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.suryaagung"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Upvotes: 2
Views: 102
Reputation: 15054
This should work:
final WebView SuryaAgung = (WebView)findViewById(R.id.main);
SuryaAgung.setWebViewClient(new WebViewClient());
SuryaAgung.getSettings().setJavaScriptEnabled(true);
SuryaAgung.loadUrl("http://localhost:8080/app");
Upvotes: 4