Answer the question
In order to leave comments, you need to log in
android studio webview how to upload a file?
Question: Why doesn't the selection menu appear when I press the button?
ps I understand that it may be necessary to connect something else in MainActivity.java.
but on the PC version everything is fine ..
MainActivity.java code
package com.example.hello;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView web = (WebView)findViewById(R.id.webView);
web.getSettings().setJavaScriptEnabled(true);
web.setWebChromeClient(new WebChromeClient());
web.loadUrl("file:///android_asset/www/index.html");
web.getSettings().setDomStorageEnabled(true);
web.getSettings().setDomStorageEnabled(true);
web.getSettings().setDatabaseEnabled(true);
web.getSettings().setDatabasePath("/data/data/" + web.getContext().getPackageName() + "/databases/");
}
}
<?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/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<input type="file" id="img" accept="image/*" onchange="fileupload(this)">
function fileupload(input) {
let file = input.files[0];
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
localStorage.setItem('img', reader.result);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question