1
votes

I am using Android Studio to create a webview app of my website. Everything works but the html file upload - pressing it does nothing, I want to be able to upload a photo from your device.

  • Compile SDK: 7.1.1
  • Min SDK: 5.1
  • Target SDK: 5.1

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dakinity.askhub">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/myTheme"
    >
    <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>

MainActivity.java

   package com.dakinity.askhub;

    import android.app.Activity;
    import android.content.ActivityNotFoundException;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Build;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.webkit.ValueCallback;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.view.Window;
    import android.view.WindowManager;
    import android.webkit.WebChromeClient;
    import android.widget.Toast;
    import android.os.Parcelable;
    import android.provider.MediaStore;
    import android.webkit.ConsoleMessage;
    import android.webkit.WebSettings.PluginState;
    import android.app.AlertDialog;
    import android.content.Context;
    import android.content.DialogInterface;

    public class MainActivity extends AppCompatActivity {
    private WebView webView;

    @Override

    public void onCreate(Bundle savedInstanceState) {
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        //WindowManager.LayoutParams.FLAG_FULLSCREEN);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //webview

        webView = (WebView) findViewById(R.id.webView);

        webView.setWebViewClient(new WebViewClient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);

        webView.loadUrl("http://151.230.249.83/");

    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                    } else {
                        finish();
                    }
                    return true;
            }

        }
        return super.onKeyDown(keyCode, event);
    }




    }

All the examples are not working for me. They either dont get flagged by the program and do nothing on my android device, or they get flagged and wont resolve or recognise some words. Setting the SDK higher makes my original code get flagged for being wrong.

I don't know what to do now. Do you know how I can get the html file upload button to work via webview app ?

Thank you!

1

1 Answers

2
votes

After many days of finding a working example, I found one here: https://github.com/OpenGeeksMe/Android-File-Chooser/blob/master/app/src/main/java/it/floryn90/webapp/MainActivity.java

Every other example failed but this one, youre welcome.