How to allow a WebView app to upload a picture from the Gallery of the device on Android Studio?

FrenchyNYC

I am in my first application in WebView. I have a page in my app that allows the user to upload a picture from the gallery of photos of the device to change the avatar.

However, when I test the app, the button doesn't do anything. I tap, tap, tap, double tap ! nothing happens...

I have seen a lot of posts, I tried a lot too, nothing seems to work, some say it is not possible in webview, others say it is not anymore the same method since Lollipop etc... In other words : I AM LOST !

Here is the code of my MainActivity.java :

package com.example.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;



public class MainActivity extends Activity {

    private WebView mWebView;

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

        mWebView = (WebView) findViewById(R.id.activity_main_webview);

        // Force links and redirects to open in the WebView instead of in a browser
        mWebView.setWebViewClient(new WebViewClient());

        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        // Use remote resource
        mWebView.loadUrl("http://urlofmywebsite");

        // Stop local links and redirects from opening in browser instead of WebView
        //mWebView.setWebViewClient(new MyAppWebViewClient());

        // Use local resource
        // mWebView.loadUrl("file:///android_asset/www/index.html");

    }

    // Prevent the back-button from closing the app
    @Override
    public void onBackPressed() {
        if(mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
Karan Singh

do you want to get link first from your server about the image you want to send, and then simply load URL to webview or you want image to go locally.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to upload an app onto a device in Android Studio

From Dev

Android Webview Upload Image from gallery or camera

From Dev

Ionic-Upload picture from camera or gallery in Android

From Dev

Picture is not showing in Gallery App in Android

From Dev

upload the picture from gallery or camera by alertdialogue

From Dev

How to map images at runtime from an Android device's Gallery to Textures in Unity app?

From Dev

How can I choose picture from android gallery using Nativescript?

From Dev

How to open the default gallery from android and receive the picked uri of the picture?

From Dev

Upload image from android app gallery to local spring server

From Dev

Installing Android app on device from Android Studio

From Dev

How to upload file from fragment webview in android?

From Dev

How to upload file from fragment webview in android?

From Dev

Android RelativeLayout Background Picture from Gallery

From Dev

SecurityException reading picture from Android gallery

From Dev

Select Image from Gallery Not Posting to App in Android Studio?

From Dev

How to set path to picture in folder in device in android appcelerator app

From Dev

How to upload photo from gallery in Android to a website with Dropzonejs?

From Dev

How to Upload the image from gallery to Parse Server in android..?

From Dev

Android Upload Image from device gallery to Amazon S3 server

From Dev

Access the mobile gallery from an android webview

From Dev

Webview - Best way to upload images from device

From Dev

Can't upload captured picture from android device to RoR webapp using form

From Dev

Android - install app from Android Studio - missing shortcut in android device

From Dev

How to open a picture in gallery

From Dev

How to upload all gallery images to a server in Android ?

From Dev

How to terminate app in Android Studio-- app running on separate device

From Dev

How to upload image from gallery to server?

From Dev

How to upload image from gallery to server?

From Dev

Unable to run project app from Android Studio to my external device

Related Related

  1. 1

    How to upload an app onto a device in Android Studio

  2. 2

    Android Webview Upload Image from gallery or camera

  3. 3

    Ionic-Upload picture from camera or gallery in Android

  4. 4

    Picture is not showing in Gallery App in Android

  5. 5

    upload the picture from gallery or camera by alertdialogue

  6. 6

    How to map images at runtime from an Android device's Gallery to Textures in Unity app?

  7. 7

    How can I choose picture from android gallery using Nativescript?

  8. 8

    How to open the default gallery from android and receive the picked uri of the picture?

  9. 9

    Upload image from android app gallery to local spring server

  10. 10

    Installing Android app on device from Android Studio

  11. 11

    How to upload file from fragment webview in android?

  12. 12

    How to upload file from fragment webview in android?

  13. 13

    Android RelativeLayout Background Picture from Gallery

  14. 14

    SecurityException reading picture from Android gallery

  15. 15

    Select Image from Gallery Not Posting to App in Android Studio?

  16. 16

    How to set path to picture in folder in device in android appcelerator app

  17. 17

    How to upload photo from gallery in Android to a website with Dropzonejs?

  18. 18

    How to Upload the image from gallery to Parse Server in android..?

  19. 19

    Android Upload Image from device gallery to Amazon S3 server

  20. 20

    Access the mobile gallery from an android webview

  21. 21

    Webview - Best way to upload images from device

  22. 22

    Can't upload captured picture from android device to RoR webapp using form

  23. 23

    Android - install app from Android Studio - missing shortcut in android device

  24. 24

    How to open a picture in gallery

  25. 25

    How to upload all gallery images to a server in Android ?

  26. 26

    How to terminate app in Android Studio-- app running on separate device

  27. 27

    How to upload image from gallery to server?

  28. 28

    How to upload image from gallery to server?

  29. 29

    Unable to run project app from Android Studio to my external device

HotTag

Archive