0

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

Ema.jar
  • 2,370
  • 1
  • 33
  • 43
Lukas
  • 1
  • 3
  • so image upload wont work as you expecting right? – Iqbal Rizky Jan 29 '17 at 22:04
  • @ntaloventi - At the moment image upload dont work. – Lukas Jan 29 '17 at 22:06
  • you can use your javascript to open some dialog to do that, do you only need to upload some files or something else? – Iqbal Rizky Jan 29 '17 at 22:09
  • @ntaloventi - I want to upload images with this html code in the webview: At the moment when you click on the "Choose a file"-Button nothing happens. – Lukas Jan 29 '17 at 22:11
  • if you want your application like web you can try chrometabs `https://developer.chrome.com/extensions/tabs` but if you want to use web view its better if you use dialog to get the file image then post with volley – Iqbal Rizky Jan 29 '17 at 22:16
  • @ntaloventi - Is it simple to upload a image with a dialog? Can you give me a link to a code that work with my code? – Lukas Jan 29 '17 at 22:22
  • maybe this suit for you `https://gist.github.com/anggadarkprince/a7c536da091f4b26bb4abf2f92926594` – Iqbal Rizky Jan 29 '17 at 22:26
  • @ntaloventi - Page not found. – Lukas Jan 29 '17 at 22:28
  • sorry you need login first, `https://gist.github.com/anggadarkprince/a7c536da091f4b26bb4abf2f92926594` – Iqbal Rizky Jan 29 '17 at 22:32
  • @ntaloventi - Still page not found. The profile https://github.com/anggadarkprince is available. – Lukas Jan 29 '17 at 22:52
  • `https://gist.githubusercontent.com/anggadarkprince/a7c536da091f4b26bb4abf2f92926594/raw/4b04317abf1e9acc0d2c1499a84b87364b83c626/MainActivity.java` – Iqbal Rizky Jan 29 '17 at 22:57
  • @ntaloventi - I think your link is only available for your account/session. I found a gist anggadarkprince / MainActivity.java - did you mean this? – Lukas Jan 29 '17 at 23:02
  • yup try to modified to suit to your code – Iqbal Rizky Jan 29 '17 at 23:03
  • @ntaloventi - I thought, you have a similar code like here: http://stackoverflow.com/questions/15725814/upload-an-image-from-camera-or-gallery-in-webview – Lukas Jan 29 '17 at 23:11
  • i'm just try to help, if you have found good one, please use as you need – Iqbal Rizky Jan 29 '17 at 23:16
  • @ntaloventi - I need help with paste it in my code. But thanks for your help. – Lukas Jan 29 '17 at 23:18

0 Answers0