I am a newbie in java. Since 5 years I program in html, php and mysql. I want to load a website in a webview with some functions.
The webview should load when the user open the app. These functions should include:
javascript enable
image upload allowed (if possible, for all android versions)
only allow the deposited domain and all other domains show a window where they can choose a installed browser just like chrome. this is importent when they click on a external link in the webview.
I have tried some things, but only the javascript and webview worked. I dont know if the currently code is the best solution.
This is my code in the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:addStatesFromChildren="false"
android:layout_height="match_parent"
android:layout_width="match_parent">
<WebView
android:id="@+id/web1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
and this is my code in the MainActivity.java
package com.example.user.testapplication;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.web1);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("https://www.website.com");
String url = myWebView.getUrl();
if (url.contains("website.com")) {
myWebView.loadUrl(url);
} else {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
myWebView.getContext().startActivity(i);
}
}
}
and here the code of AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.testapplication">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:layout_width="match_parent"
android:layout_height="match_parent">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thanks in advance for your assistance