• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Webview app image upload not working

Marodo

Lurker
Hi,

I created a very simple webview app in Android Studio (I'm a website developer so not really an app developer).

The site is a standard html5 css3 site that allows skiers to sell and buy used ski gear, so it uses auction technology.

Part of the listing process involves clicking an 'Add Images' button which allows users to navigate to images on the devices/cloud storage, but, on the Android webview app all I see is a button that says 'Choose Files' (NOT 'Add Images', which is weird), but when I click it nothing happens, which means that the app is essentially useless as is.

I obviously need to tweek the code (I use Android Studio 3.5.1), but I don't know what code to tweek.

Can you help?

Code below

Activity.main.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <WebView
        android:id="@+id/wb"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>


MainActivity.java

Java:
package com.shnohdotcom.shnoh;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
     private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView= findViewById(R.id.wb);
        webView.loadUrl("https://www.shnoh.com/");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient (new WebViewClient());
    }
}


AndroidManifest.xml

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

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <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>
 
Yes, it works perfectly as a website on a phone, but not as a webview app. As I said in my original question, even the button has a different name on the app.

You've tested the target site with a regular browser and confirmed that images upload?

Yes

You've tested the target site with a regular browser and confirmed that images upload?
Yes, it works perfectly as a website on a phone, but not as a webview app. As I said in my original question, even the button has a different name on the app.
 
Last edited by a moderator:
The question here looks almost exactly like what you're describing
https://stackoverflow.com/questions/5907369/file-upload-in-webview

"However, in the android 3.0 emulator / AVD, when I click on "Choose file", nothing happens, no file dialog is opened!!!"

Seems to be a few answers, depending on your version. Looks like you need to add support for the file selector in your Android code.

In the end I had a look around the internet and found a chap called Zid who's good with android, I emailed him, told him my problem, he asked for .text copies of my MainActivity and Manifest, then he emailed me altered versions and boom it worked!
 
Back
Top Bottom